QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#722728 | #9465. 基础 01 练习题 | liujunyi123 | 30 | 1147ms | 243156kb | C++14 | 4.4kb | 2024-11-07 20:03:26 | 2024-11-07 20:03:27 |
Judging History
answer
#include<bits/stdc++.h>
#define ull unsigned long long
using namespace std;
const int N=2e5+5;
int read(){int x=0,f=1;char ch=getchar();
while(ch<'0'||ch>'9'){if(ch==-1)f=-1;ch=getchar();}
while(ch>='0'&&ch<='9')x=(x<<1)+(x<<3)+ch-'0',ch=getchar();
return x*f;
}
void write(int x){
if(x<10)return putchar(x^48),void();
write(x/10),putchar((x%10)^48);
}
int n,q,ty,f[N],s[N],sz[N],sz2[N],id[N],rk[N],nxt[N],lst[N];
vector<pair<int,int> > g[N];
ull bs=131,pw[N],p1[N];
struct HSH{
vector<pair<int,int> > g[N];
int rt[N],tot;
struct node{bool tg;int ls,rs;ull sum;}tr[N*60];
void nw(int &o,int p){o=++tot,tr[o]=tr[p];}
void addtag(int o,int len){tr[o].sum=p1[len]-tr[o].sum,tr[o].tg^=1;}
void downtag(int o,int l,int r,int mid){
if(tr[o].tg)nw(tr[o].ls,tr[o].ls),nw(tr[o].rs,tr[o].rs),addtag(tr[o].ls,mid-l+1),addtag(tr[o].rs,r-mid),tr[o].tg=0;
}
void update(int &o,int p,int l,int r,int x,int y){
if(l!=r)downtag(p,l,r,(l+r)>>1);nw(o,p);
if(x<=l&&r<=y)return addtag(o,r-l+1);
int mid=(l+r)>>1;
if(x<=mid)update(tr[o].ls,tr[p].ls,l,mid,x,y);
if(y>mid)update(tr[o].rs,tr[p].rs,mid+1,r,x,y);
tr[o].sum=tr[tr[o].ls].sum*pw[r-mid]+tr[tr[o].rs].sum;
}
bool query(int o,int p,int l,int r){
if(l==r)return tr[o].sum>tr[p].sum;
int mid=(l+r)>>1;downtag(o,l,r,mid),downtag(p,l,r,mid);
// cout<<o<<" "<<p<<" "<<l<<" "<<r<<" "<<tr[tr[o].ls].sum<<" "<<tr[tr[p].ls].sum<<endl;
if(tr[tr[o].ls].sum==tr[tr[p].ls].sum)return query(tr[o].rs,tr[p].rs,mid+1,r);
return query(tr[o].ls,tr[p].ls,l,mid);
}
void init(){
for(int i=1;i<=n;i++){rt[i]=rt[i-1];
for(auto x:g[i])update(rt[i],rt[i],1,n,x.first,x.second);
}
// for(int i=2;i<=3;i++)
// for(int j=2;j<=3;j++)cout<<i<<" "<<j<<" "<<endl,query(rt[i],rt[j],1,n);
}
}T;
bool cmp(int x,int y){return T.query(T.rt[x],T.rt[y],1,n);}
struct tree{bool tg;struct node{int mx,mn;}s[2];
void addtag(){tg^=1,swap(s[0],s[1]);}
void merge(tree&x,tree&y){
s[0].mx=max(x.s[0].mx,y.s[0].mx);
s[1].mx=max(x.s[1].mx,y.s[1].mx);
s[0].mn=min(x.s[0].mn,y.s[0].mn);
s[1].mn=min(x.s[1].mn,y.s[1].mn);
}
}tr[N<<2];
void build(int o,int l,int r){
if(l==r){
tr[o].s[1].mx=0,tr[o].s[1].mn=N;
tr[o].s[0].mx=tr[o].s[0].mn=rk[l];
return ;
}
int mid=(l+r)>>1;
build(o<<1,l,mid),build(o<<1|1,mid+1,r);
tr[o].merge(tr[o<<1],tr[o<<1|1]);
// cout<<l<<" "<<r<<" "<<tr[o].s[1].mn<<endl;
}
void downtag(int o){if(tr[o].tg)tr[o<<1].addtag(),tr[o<<1|1].addtag(),tr[o].tg=0;}
void update(int o,int l,int r,int x,int y){
if(x<=l&&r<=y)return tr[o].addtag();
int mid=(l+r)>>1;downtag(o);
if(x<=mid)update(o<<1,l,mid,x,y);
if(y>mid)update(o<<1|1,mid+1,r,x,y);
tr[o].merge(tr[o<<1],tr[o<<1|1]);
}
int find(int x){return x==f[x]?x:f[x]=find(f[x]);}
int d[1005][1005];
int main(){pw[0]=1,p1[0]=0;
for(int i=1;i<N;i++)p1[i]=p1[i-1]+pw[i-1],pw[i]=pw[i-1]*bs;
// freopen("1.in","r",stdin);
// freopen("1.out","w",stdout);
scanf("%d%d%d",&n,&q,&ty);
for(int i=1;i<=n;i++)id[i]=i;
for(int i=1,a,b,x,y;i<=q;i++){
scanf("%d%d%d%d",&a,&b,&x,&y);
T.g[a].push_back(make_pair(x,y));
T.g[b+1].push_back(make_pair(x,y));
g[x].push_back(make_pair(a,b));
g[y+1].push_back(make_pair(a,b));
// d[a][x]^=1,d[b+1][x]^=1,d[a][y+1]^=1,d[b+1][y+1]^=1;
}
/*
for(int i=1;i<=n;i++){
for(int j=1;j<=n;j++){
d[i][j]^=d[i-1][j]^d[i][j-1]^d[i-1][j-1];
cout<<d[i][j];
}
cout<<endl;
}
for(int j=1;j<=n;j++){
for(int i=1;i<=n;i++)if(d[i][j])cout<<i<<" "<<j+n<<endl;else cout<<j+n<<" "<<i<<endl;
cout<<endl;
}*/
T.init(),sort(id+1,id+n+1,cmp);
for(int i=1;i<=n;i++)rk[id[i]]=i,f[i]=i,sz[i]=1,lst[i]=i-1,nxt[i]=i+1;//cout<<id[i]<<endl;
// cout<<endl;
build(1,1,n);
long long ans=0;
for(int i=1,ct=0;i<=n;i++){
for(auto x:g[i])update(1,1,n,x.first,x.second);
int mn=tr[1].s[0].mn,mx=tr[1].s[1].mx;
// cout<<mn<<" "<<mx<<endl;
if(mn<=n&&mx>0){
mn=find(mn),mx=find(mx);
if(mx>=mn){
int s1=0,s2=0;
// cout<<mn<<" "<<mx<<endl;
for(int p=mn;p<=mx;p=nxt[p]){
ans-=1ll*sz[p]*sz2[p];
s1+=sz[p];
s2+=sz2[p];
ct-=sz[p]>1;
if(p!=mn)s2+=s[p];
f[p]=mn;
}
s2++,ct++;
sz[mn]=s1,sz2[mn]=s2;
// cout<<sz[mn]<<" "<<sz2[mn]<<endl;
ans+=1ll*sz[mn]*sz2[mn];
nxt[mn]=nxt[mx];
lst[nxt[mx]]=mn;
}else {
mn=find(mn),s[mn]++;
}
}
// cout<<ct<<endl;
if(ty||i==n)printf("%lld ",1ll*n*i-ans+ct);
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Subtask #1:
score: 5
Accepted
Test #1:
score: 5
Accepted
time: 0ms
memory: 28412kb
input:
4 1000 0 2 3 1 2 1 3 1 3 1 2 1 2 1 2 3 4 1 4 2 4 1 3 1 2 1 4 1 2 1 3 1 4 3 3 2 3 1 2 2 4 4 4 1 3 3 3 3 4 3 4 3 4 2 3 1 1 1 2 2 4 1 4 3 4 3 4 1 2 1 2 2 3 3 4 3 3 1 2 4 4 4 4 2 4 1 4 1 1 1 1 1 3 2 3 2 3 1 1 2 4 2 3 2 4 3 3 1 4 3 3 3 3 1 3 3 3 2 3 2 4 3 3 2 2 1 3 2 4 1 3 1 2 3 4 1 2 2 3 1 3 1 1 1 2 1 2...
output:
1
result:
ok 1 number(s): "1"
Test #2:
score: 5
Accepted
time: 0ms
memory: 28600kb
input:
4 1000 0 1 4 3 3 2 3 4 4 3 4 3 4 3 4 1 2 1 4 2 4 2 3 1 3 3 4 2 4 2 3 3 3 3 4 1 3 1 3 1 4 2 3 1 3 1 1 2 2 1 4 3 4 1 4 1 3 1 2 3 4 1 2 1 2 2 3 1 4 2 2 2 2 1 3 1 3 2 2 2 4 1 2 1 4 1 1 1 1 1 2 3 4 4 4 1 3 2 4 1 3 1 1 1 3 1 4 2 2 2 3 1 2 2 2 1 2 1 2 1 4 1 4 2 4 1 2 1 3 1 2 1 3 2 4 2 2 1 2 1 1 1 2 1 3 2 4...
output:
1
result:
ok 1 number(s): "1"
Test #3:
score: 5
Accepted
time: 6ms
memory: 26592kb
input:
4 1000 0 1 4 1 2 1 4 2 2 1 4 3 4 2 4 4 4 2 3 3 4 2 4 2 4 1 2 2 2 4 4 2 4 1 3 1 3 1 4 1 4 3 3 3 4 4 4 2 3 2 3 1 4 2 2 1 3 2 3 2 4 2 2 1 4 1 2 2 3 1 4 1 3 4 4 1 4 3 4 1 4 1 2 1 2 1 2 1 3 2 2 3 3 1 2 1 4 1 1 1 4 2 2 1 4 1 4 3 4 2 4 2 4 2 2 1 4 3 4 1 3 2 3 2 4 1 3 1 4 1 3 1 4 3 3 1 3 1 2 1 3 3 3 1 4 1 4...
output:
5
result:
ok 1 number(s): "5"
Subtask #2:
score: 10
Accepted
Test #4:
score: 10
Accepted
time: 157ms
memory: 195964kb
input:
50 200000 0 1 45 2 6 29 44 2 6 31 37 2 50 2 37 1 19 7 13 8 38 38 46 19 38 10 30 30 46 22 42 1 45 5 35 24 27 10 36 19 31 20 47 17 35 7 9 23 42 15 26 31 42 7 8 7 42 1 26 33 48 2 5 30 36 17 44 21 44 5 44 24 36 19 47 15 17 29 36 2 42 31 34 11 41 9 24 12 30 30 43 8 20 2 12 13 20 11 12 10 15 14 22 3 29 2 ...
output:
1
result:
ok 1 number(s): "1"
Test #5:
score: 10
Accepted
time: 2ms
memory: 24352kb
input:
50 70 0 1 50 1 50 24 50 1 1 50 50 2 2 34 50 3 3 36 50 4 4 32 50 5 5 18 50 6 6 12 50 7 7 6 50 8 8 28 50 9 9 38 50 10 10 4 50 11 11 26 50 12 12 14 50 13 13 46 50 14 14 2 50 15 15 8 50 16 16 44 50 17 17 10 50 18 18 30 50 19 19 22 50 20 20 48 50 21 21 20 50 22 22 42 50 23 23 40 50 24 24 16 50 25 25 16 5...
output:
2280
result:
ok 1 number(s): "2280"
Test #6:
score: 10
Accepted
time: 5ms
memory: 26488kb
input:
50 100 0 2 49 1 1 23 28 2 2 19 32 3 3 21 30 4 4 20 31 5 5 22 29 6 6 12 39 7 7 15 36 8 8 7 44 9 9 3 48 10 10 10 41 11 11 5 46 12 12 14 37 13 13 13 38 14 14 4 47 15 15 6 45 16 16 17 34 17 17 25 26 18 18 1 50 19 19 9 42 20 20 11 40 21 21 16 35 22 22 24 27 23 23 8 43 24 24 18 33 25 25 11 40 26 26 14 37 ...
output:
339
result:
ok 1 number(s): "339"
Test #7:
score: 10
Accepted
time: 4ms
memory: 26600kb
input:
50 500 0 1 2 1 14 3 4 1 3 5 6 1 12 7 8 1 9 9 10 1 15 11 12 1 11 13 14 1 13 15 16 1 17 17 18 1 16 19 20 1 20 21 22 1 2 23 24 1 10 25 26 1 4 27 28 1 8 29 30 1 19 31 32 1 21 33 34 1 24 35 36 1 23 37 38 1 6 39 40 1 18 41 42 1 25 43 44 1 5 45 46 1 22 47 48 1 1 49 50 1 7 35 36 26 26 41 42 26 26 27 28 27 2...
output:
51
result:
ok 1 number(s): "51"
Subtask #3:
score: 0
Runtime Error
Test #8:
score: 0
Runtime Error
input:
5000 200000 0 1438 2561 3478 4930 1740 4634 87 3003 590 3275 1376 1681 2035 2793 2004 4945 567 3159 550 4470 61 3039 3431 3519 2654 3834 3460 4960 591 3560 409 443 345 2599 746 2891 1288 4570 1577 4402 249 377 1951 4534 2411 2455 294 1192 1679 3153 1645 4259 1735 1856 601 668 477 4881 411 2094 424 1...
output:
result:
Subtask #4:
score: 0
Runtime Error
Test #14:
score: 0
Runtime Error
input:
5000 200000 1 565 4401 1659 1826 429 1640 2999 3495 572 3994 9 3863 3844 4284 2307 3144 1054 1943 358 2592 727 4248 29 1171 1685 2392 4559 4929 1149 2787 1204 1947 2349 2619 405 998 1910 2786 25 1275 912 3475 4384 4387 3822 4895 1849 4548 3082 4749 3457 4220 3174 4885 117 1085 2517 3919 4325 4869 17...
output:
result:
Subtask #5:
score: 15
Accepted
Test #21:
score: 15
Accepted
time: 902ms
memory: 234592kb
input:
200000 200000 1 1 2 1 6 3 4 1 1 5 6 1 5 7 8 1 3 9 10 1 3 11 12 1 6 13 14 1 5 15 16 1 6 17 18 1 6 19 20 1 1 21 22 1 4 23 24 1 5 25 26 1 2 27 28 1 4 29 30 1 3 31 32 1 2 33 34 1 6 35 36 1 3 37 38 1 2 39 40 1 2 41 42 1 3 43 44 1 1 45 46 1 2 47 48 1 3 49 50 1 4 51 52 1 5 53 54 1 1 55 56 1 5 57 58 1 5 59 ...
output:
200000 400000 532619 597930 598645 533081 733081 933081 631687 831687 1031687 1064777 1264777 1464777 1664777 1864777 1897874 2097874 2297874 2330961 2530961 2730961 2764057 2964057 3164057 3364057 3564057 3764057 3964057 3997153 4197153 4397153 4597153 4797153 4997153 5197153 5230249 5430249 563024...
result:
ok 200000 numbers
Test #22:
score: 15
Accepted
time: 716ms
memory: 229932kb
input:
200000 200000 1 1 4 1 2 1 3 3 4 1 6 5 6 1 2 7 8 1 2 9 10 1 6 11 12 1 2 13 14 1 3 15 16 1 3 17 18 1 6 19 20 1 1 21 22 1 5 23 24 1 1 25 26 1 6 27 28 1 1 29 30 1 1 31 32 1 1 33 34 1 5 35 36 1 3 37 38 1 1 39 40 1 2 41 42 1 6 43 44 1 3 45 46 1 4 47 48 1 3 49 50 1 4 51 52 1 4 53 54 1 1 55 56 1 4 57 58 1 3...
output:
200000 400000 599992 799992 999981 1199971 1399971 1599938 1799938 1999921 2199911 2399901 2599901 2799901 2999891 3199869 3399858 3599847 3799806 3999793 4199686 4399686 4599671 4799656 4999593 5199551 5399533 5599515 5799469 5999421 6199421 6399371 6599371 6799319 6999137 7199044 7399015 7598986 7...
result:
ok 200000 numbers
Test #23:
score: 15
Accepted
time: 726ms
memory: 229664kb
input:
200000 200000 1 1 2 1 2 1 6 3 4 1 1 5 6 1 2 7 8 1 5 9 10 1 2 11 12 1 6 13 14 1 1 15 16 1 3 17 18 1 5 19 20 1 3 21 22 1 6 23 24 1 5 25 26 1 2 27 28 1 1 29 30 1 3 31 32 1 2 33 34 1 2 35 36 1 3 37 38 1 5 39 40 1 6 41 42 1 2 43 44 1 5 45 46 1 5 47 48 1 3 49 50 1 5 51 52 1 2 53 54 1 5 55 56 1 6 57 58 1 1...
output:
200000 400000 600000 800000 1000000 1199971 1399965 1599952 1799945 1999929 2199901 2399869 2599833 2799819 2999819 3199819 3399777 3599746 3799729 3999712 4199695 4399659 4599641 4799602 4999539 5199518 5399497 5599476 5799476 5999476 6199429 6399353 6599301 6799276 6999221 7199195 7399137 7599110 ...
result:
ok 200000 numbers
Test #24:
score: 15
Accepted
time: 937ms
memory: 238232kb
input:
200000 200000 1 1 2 3 6 3 4 3 6 5 6 3 5 7 8 3 6 9 10 3 4 11 12 2 5 13 14 2 5 15 16 2 2 17 18 1 1 19 20 2 3 21 22 3 5 23 24 2 5 25 26 1 5 27 28 2 5 29 30 1 4 31 32 1 1 33 34 1 6 35 36 3 7 37 38 3 7 39 40 1 6 41 42 2 5 43 44 3 7 45 46 1 5 47 48 2 3 49 50 2 7 51 52 1 2 53 54 3 8 55 56 3 5 57 58 3 5 59 ...
output:
200000 244003 133246 133117 111726 66913 1 1 200001 200001 400001 400001 600001 800001 1000001 1200001 1400001 1400001 1400001 1600001 1800001 1800001 2000001 2200001 2400001 2600001 2600001 2600001 2800001 3000001 3000001 3000001 3200001 3200001 3400001 3600001 3600001 3800001 4000001 4000001 40000...
result:
ok 200000 numbers
Test #25:
score: 15
Accepted
time: 1147ms
memory: 241084kb
input:
200000 200000 1 62179 62180 166600 166600 168902 168904 109106 109107 71739 71741 40856 40856 68155 68155 50355 50355 82427 82427 131433 131435 134495 134497 97523 97524 100523 100523 163640 163642 103078 103078 39321 39321 75997 75997 52778 52780 141945 141946 67489 67489 20781 20782 198096 198098 ...
output:
200000 399993 599993 799980 999965 1199946 1399935 1599889 1799873 1999848 2199848 2399848 2599801 2799801 2999801 3199759 3399759 3599725 3799611 3999581 4199551 4399457 4599372 4799263 4999165 5199061 5399014 5598923 5798828 5998828 6198633 6398501 6598311 6798165 6998013 7197942 7397721 7597645 7...
result:
ok 200000 numbers
Test #26:
score: 15
Accepted
time: 1059ms
memory: 240928kb
input:
200000 200000 1 172635 172635 165118 165120 182060 182062 140709 140711 79621 79622 120595 120597 22131 22132 38357 38357 15637 15637 73583 73583 163025 163027 90579 90579 98127 98129 186936 186938 15578 15580 67768 67769 170985 170986 105541 105542 166284 166285 199715 199715 179347 179347 86139 86...
output:
200000 400000 600000 799989 999965 1199941 1399911 1599889 1799849 1999794 2199771 2399771 2599715 2799677 2999611 3199611 3399511 3599416 3799345 3999270 4199227 4399070 4598981 4798867 4998813 5198713 5398585 5598451 5798207 5998057 6197985 6397826 6597826 6797691 6997521 7197377 7397377 7597163 7...
result:
ok 200000 numbers
Test #27:
score: 15
Accepted
time: 1099ms
memory: 243156kb
input:
200000 200000 1 192777 192779 177750 177752 143767 143769 170842 170843 26652 26654 75434 75435 43426 43427 188344 188345 139929 139929 172505 172506 176663 176665 58244 58246 32815 32815 193800 193801 148127 148127 103366 103368 136791 136793 152591 152591 33978 33979 63334 63334 108117 108117 1561...
output:
200000 400000 599993 799965 999946 1199929 1399917 1599881 1799821 1999801 2199737 2399653 2599533 2799469 2999356 3199281 3399236 3599137 3799089 3999041 4199041 4399041 4599041 4799041 4998972 5198879 5398713 5598657 5798551 5998389 6198327 6398181 6598087 6798087 6997991 7197800 7397729 7597394 7...
result:
ok 200000 numbers
Subtask #6:
score: 0
Runtime Error
Test #28:
score: 0
Runtime Error
input:
200000 200000 0 91264 123676 6826 154505 121351 188051 108158 131448 65413 163961 26771 116304 93852 110556 34929 187363 31794 142162 33578 38712 26574 67763 178013 197235 46436 146042 95 122860 11683 50463 60177 195245 60862 194711 37817 97212 144366 176271 113551 171098 120095 170517 73555 167299 ...
output:
result:
Subtask #7:
score: 0
Runtime Error
Test #37:
score: 0
Runtime Error
input:
100000 200000 1 1 22878 1 2 1 7957 3 4 1 21779 5 6 1 34321 7 8 1 41692 9 10 1 49473 11 12 1 10254 13 14 1 43995 15 16 1 46975 17 18 1 668 19 20 1 25996 21 22 1 24975 23 24 1 43259 25 26 1 4174 27 28 1 39330 29 30 1 35462 31 32 1 27523 33 34 1 5574 35 36 1 47955 37 38 1 47013 39 40 1 3846 41 42 1 276...