QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#445316 | #8809. Telephone Plans | Crysfly | 0 | 26ms | 144412kb | C++17 | 2.7kb | 2024-06-16 01:08:48 | 2024-06-16 01:08:48 |
Judging History
answer
// what is matter? never mind.
//#pragma GCC optimize("Ofast")
//#pragma GCC optimize("unroll-loops")
//#pragma GCC target("sse,sse2,sse3,sse4,popcnt,abm,mmx,avx,avx2")
#include<bits/stdc++.h>
#define For(i,a,b) for(int i=(a);i<=(b);++i)
#define Rep(i,a,b) for(int i=(a);i>=(b);--i)
#define ll long long
//#define int long long
#define ull unsigned long long
#define SZ(x) ((int)((x).size()))
#define ALL(x) (x).begin(),(x).end()
using namespace std;
inline ll read()
{
char c=getchar();ll x=0;bool f=0;
for(;!isdigit(c);c=getchar())f^=!(c^45);
for(;isdigit(c);c=getchar())x=(x<<1)+(x<<3)+(c^48);
if(f)x=-x;return x;
}
#define fi first
#define se second
#define pb push_back
#define mkp make_pair
typedef pair<int,int>pii;
typedef vector<int>vi;
#define maxn 1000005
#define inf 0x3f3f3f3f
int O,n,Q;
set<int>e[maxn],c[maxn*2];
struct node{
int u,pa;
set<int>::iterator it;
};
ll res1[maxn*3],res2[maxn*3];
int fa[maxn*2],idx;
ll add(int u,int v){
// cout<<"add "<<u<<" "<<v<<"\n";
e[u].insert(v),e[v].insert(u);
int fu=fa[u],fv=fa[v];
if(c[fu].size()<c[fv].size()) swap(u,v),swap(fu,fv);
ll ans=1ll*c[fu].size()*c[fv].size();
for(int x:c[fv]) c[fu].insert(x),fa[x]=fu;
c[fv].clear();
// cout<<"ans "<<ans<<"\n";
return ans;
}
queue<node>q[2];
vi s[2];
ll del(int u,int v){
e[u].erase(v),e[v].erase(u);
while(q[0].size()) q[0].pop();
while(q[1].size()) q[1].pop();
s[0].pb(u),s[1].pb(v);
if(e[u].size()) q[0].push((node){u,0,e[u].begin()});
if(e[v].size()) q[1].push((node){v,0,e[v].begin()});
while(q[0].size() && q[1].size()) {
int o=(s[1].size()<s[0].size());
auto [u,pa,it]=q[o].front(); q[o].pop();
int v=*it;
if(v!=pa){
s[o].pb(v);
if(e[v].size()) q[o].push({v,u,e[v].begin()});
}
++it;
if(it==e[u].end()) continue;
if(*it==pa) ++it;
if(it==e[u].end()) continue;
q[o].push({u,pa,it});
}
if(!q[0].size() && (q[1].size() || s[0].size()<s[1].size())) swap(u,v),swap(s[0],s[1]);
int fu=fa[u];
ll ans=1ll*s[1].size()*(c[fu].size()-s[1].size());
assert(s[1].size()*2<=c[fu].size());
++idx;
for(int x:s[1]) fa[x]=idx,c[fu].erase(x),c[idx].insert(x);
return ans;
}
signed main()
{
// freopen("my.out","w",stdout);
O=read(),n=read(),Q=read(); idx=n;
For(i,1,n) c[i].insert(i);
For(i,1,n*2) fa[i]=i;
ll lst=0;
For(i,1,Q){
int op=read();
res1[i]=res1[i-1],res2[i]=res2[i-1];
if(op==1){
int u=read(),v=read();
if(O)u^=lst,v^=lst;
res1[i]+=add(u,v);
}
if(op==2){
int u=read(),v=read();
if(O)u^=lst,v^=lst;
res2[i]+=del(u,v);
}
if(op==3){
ll t=read();
if(O)t^=lst;
lst=res1[i]-res2[i-t];
cout<<lst<<"\n";
}
}
return 0;
}
/*
*/
詳細信息
Subtask #1:
score: 0
Runtime Error
Test #1:
score: 3
Accepted
time: 26ms
memory: 144152kb
input:
0 1 147 3 0 3 0 3 1 3 1 3 0 3 5 3 5 3 1 3 1 3 4 3 8 3 2 3 10 3 13 3 10 3 8 3 8 3 0 3 16 3 3 3 1 3 20 3 2 3 10 3 16 3 13 3 17 3 12 3 22 3 7 3 8 3 2 3 12 3 32 3 12 3 31 3 2 3 0 3 21 3 24 3 28 3 32 3 9 3 18 3 26 3 11 3 45 3 35 3 14 3 34 3 49 3 31 3 43 3 11 3 21 3 50 3 4 3 11 3 31 3 51 3 28 3 26 3 18 3 ...
output:
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
result:
ok 147 lines
Test #2:
score: 3
Accepted
time: 12ms
memory: 144412kb
input:
0 2 10 1 1 2 3 1 3 1 3 2 3 3 3 3 3 3 2 1 2 3 2 3 3
output:
1 1 1 1 1 1 1 1
result:
ok 8 lines
Test #3:
score: 0
Runtime Error
input:
0 30 150 1 14 10 3 1 1 14 6 1 3 6 3 4 3 4 1 2 3 3 0 3 5 1 2 9 1 11 9 3 8 1 19 11 3 6 1 8 19 3 14 3 10 1 27 8 3 15 1 27 28 1 28 20 3 0 3 3 1 20 7 1 7 23 3 13 3 5 1 24 23 3 0 3 28 1 24 13 3 5 3 32 3 1 3 13 1 30 13 3 25 1 30 16 1 15 16 3 22 1 29 15 3 13 1 29 25 1 25 1 1 1 18 3 17 3 8 3 10 1 26 18 3 46 ...
output:
result:
Subtask #2:
score: 0
Runtime Error
Test #29:
score: 2
Accepted
time: 16ms
memory: 144148kb
input:
1 1 147 3 0 3 0 3 1 3 1 3 3 3 0 3 6 3 6 3 0 3 2 3 0 3 5 3 12 3 1 3 2 3 10 3 13 3 15 3 3 3 12 3 20 3 18 3 10 3 12 3 2 3 12 3 14 3 26 3 12 3 24 3 7 3 7 3 6 3 29 3 32 3 16 3 23 3 14 3 25 3 13 3 13 3 31 3 20 3 26 3 0 3 40 3 23 3 28 3 35 3 1 3 31 3 2 3 34 3 37 3 3 3 39 3 17 3 4 3 41 3 11 3 16 3 48 3 10 3...
output:
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
result:
ok 147 lines
Test #30:
score: 2
Accepted
time: 12ms
memory: 144208kb
input:
1 2 10 1 1 2 3 1 3 1 3 1 3 1 3 1 3 2 3 6 2 0 3 3 2
output:
1 1 1 1 1 1 1 1
result:
ok 8 lines
Test #31:
score: 0
Runtime Error
input:
1 30 150 1 21 13 3 1 1 9 20 3 2 3 2 1 18 11 1 18 0 3 6 3 9 3 8 1 12 9 3 8 3 7 1 10 9 3 5 3 24 3 26 3 28 1 6 16 3 6 3 14 1 15 23 3 21 3 48 1 60 47 3 53 3 37 1 35 53 3 56 1 57 59 1 59 37 3 63 3 95 3 94 1 92 79 3 65 1 90 81 1 95 81 3 75 3 111 3 118 3 100 1 124 98 1 101 98 3 121 3 132 3 137 3 153 1 141 ...
output:
result:
Subtask #3:
score: 0
Skipped
Dependency #1:
0%
Subtask #4:
score: 0
Skipped
Dependency #2:
0%
Subtask #5:
score: 0
Skipped
Dependency #3:
0%
Subtask #6:
score: 0
Skipped
Dependency #4:
0%
Subtask #7:
score: 0
Skipped
Dependency #6:
0%