社区讨论
史山代码求 Hack
P11619[PumpkinOI Round 1] 种南瓜参与者 1已保存回复 0
讨论操作
快速查看讨论及其快照的属性,并进行相关操作。
- 当前回复
- 0 条
- 当前快照
- 1 份
- 快照标识符
- @mj0vi521
- 此快照首次捕获于
- 2025/12/11 11:23 2 个月前
- 此快照最后确认于
- 2025/12/13 15:45 2 个月前
CPP
#include<bits/stdc++.h>
using namespace std;
#ifndef ONLINE_JUDGE
#define debug(...)do{\// my debug
cerr<<"debug in function "<<__FUNCTION__<<",line "<<__LINE__<<"\n";\
string s=#__VA_ARGS__,s2="";\
vector<string>v;\
int openingbracket=0;\
for(auto i:s){\
if(i==','&&!openingbracket){\
v.push_back(s2);\
s2="";\
}else{\
s2+=i;\
if(i=='('||i=='['||i=='{')++openingbracket;\
if(i==')'||i==']'||i=='}')--openingbracket;\
}\
}\
v.push_back(s2);\
vector<long long>v2={__VA_ARGS__};\
for(int i=0;i<v.size()-1;i++){\
cerr<<v[i]<<"="<<v2[i]<<"\n";\
}\
cerr<<v[v.size()-1]<<"="<<v2[v2.size()-1]<<"\n\n";\
}while(false)
#else
#define _1145141919810_(...)
#define debug(...) void(_1145141919810_(("1"1(4)5:1[4]{1};9,1`9@8 T^T 1$0)))// ?
#endif
int n,m,k;
class Segtree{
int n;
public:
vector<vector<array<int,2>>>tree;
Segtree(int _n):n(_n+3){
tree.assign(n<<2,decltype(tree)::value_type());
}
void add(int l,int r,int p,int L,int R,array<int,2>tim){
if(L>r||R<l)return;
if(L<=l&&r<=R){
tree[p].emplace_back(tim);
return;
}
int mid=l+r>>1;
add(l,mid,p<<1,L,R,tim);
add(mid+1,r,p<<1|1,L,R,tim);
}
};
typedef int ll;
struct node{
ll sum{},ls{},rs{},lazy{};
};
class segtree{
vector<node>tree;
void pushdown(int l,int r,int p){
if(!tree[p].ls)tree[p].ls=tree.size(),tree.emplace_back();
if(!tree[p].rs)tree[p].rs=tree.size(),tree.emplace_back();
if(!tree[p].lazy)return;
int mid=l+r>>1;
tree[tree[p].ls].sum+=(mid-l+1)*tree[p].lazy;
tree[tree[p].rs].sum+=(r-mid)*tree[p].lazy;
tree[tree[p].ls].lazy+=tree[p].lazy;
tree[tree[p].rs].lazy+=tree[p].lazy;
tree[p].lazy=0;
}
void pushup(int p){
tree[p].sum=0;
if(tree[p].ls)tree[p].sum+=tree[tree[p].ls].sum;
if(tree[p].rs)tree[p].sum+=tree[tree[p].rs].sum;
}
void add(int l,int r,int p,int s,int t,ll c){
if(!p||l>t||r<s)return;
if(s<=l&&r<=t){
tree[p].sum+=(r-l+1)*c,tree[p].lazy+=c;
return;
}
pushdown(l,r,p);
int mid=l+r>>1;
add(l,mid,tree[p].ls,s,t,c);
add(mid+1,r,tree[p].rs,s,t,c);
pushup(p);
}
ll query(int l,int r,int p,int s,int t){
if(!p||l>t||r<s)return 0;
if(s<=l&&r<=t)return tree[p].sum;
int mid=l+r>>1;
ll ans=0;
pushdown(l,r,p);
ans+=query(l,mid,tree[p].ls,s,t);
ans+=query(mid+1,r,tree[p].rs,s,t);
return ans;
}
public:
segtree(){tree=vector<node>(2);}
void add(int l,int r,ll c){
add(0,1e9,1,l,r,c);
}
ll query(int l,int r){
return query(0,1e9,1,l,r);
}
};
void solve(Segtree&sgt,segtree&sg,vector<string>&now,int l,int r,int p,bool k=false){
for(auto[l0,r0]:sgt.tree[p]){
k|=(sg.query(l0-1,l0-1)>0||sg.query(r0,r0)>0);
debug(l0,r0,sg.query(l0-1,l0-1),sg.query(r0,r0));
if(l0<r0)sg.add(l0,r0-1,1);
}
debug(l,r,k,(int)sgt.tree[p].size());
if(l==r){
now.push_back(k?"No":"Yes");
for(auto[l,r]:sgt.tree[p])if(l<r)sg.add(l,r-1,-1);
return;
}
int mid=l+r>>1;
solve(sgt,sg,now,l,mid,p<<1,k);
solve(sgt,sg,now,mid+1,r,p<<1|1,k);
for(auto[l,r]:sgt.tree[p])if(l<r)sg.add(l,r-1,-1);
}
map<int,array<int,2>>mp;
int main(){
ios::sync_with_stdio(false);
cin.tie(nullptr);
cout.tie(nullptr);
cin>>n>>k;
segtree sgtree;
Segtree sgt(k);
for(int i=1;i<=k;i++){
int op,l,r,j;
cin>>op;
if(op==1)
cin>>l>>r,
mp[i]=(l<r?array<int,2>{l,r}:array<int,2>{r,l});
if(op==2){
cin>>j;
sgt.add(1,k,1,j,i-1,mp[j]);
mp.erase(j);
}
}
for(auto[i,j]:mp){
sgt.add(1,k,1,i,k,j);
}
vector<string>ans;
solve(sgt,sgtree,ans,1,k,1);
for(auto i:ans)cout<<i<<"\n";
return 0;
}
回复
共 0 条回复,欢迎继续交流。
正在加载回复...