QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#649414 | #9465. 基础 01 练习题 | gyydp123_LIM | 0 | 1335ms | 345792kb | C++14 | 4.1kb | 2024-10-17 23:25:14 | 2024-10-17 23:25:16 |
Judging History
answer
#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/priority_queue.hpp>
#define For(i,j,k) for(int i=(j);i<=(k);++i)
#define ForDown(i,j,k) for(int i=(j);i>=(k);--i)
#define Debug(fmt, args...) fprintf(stderr,"(function %s, line #%d): " fmt,__func__,__LINE__,##args),fflush(stderr)
#define debug(fmt, args...) fprintf(stderr,fmt,##args),fflush(stderr)
#define within :
#define LJY main
using namespace std;
typedef long long ll;
const int N=2e5+5,B=37,mod=998244353,inf=1e9;
mt19937 rnd(chrono::system_clock::now().time_since_epoch().count());
inline int read(){
char ch=getchar();int x=0,f=1;
while(ch<'0'||ch>'9'){if(ch=='-') f=-1;ch=getchar();}
while(ch>='0'&&ch<='9')
x=(x<<3)+(x<<1)+(ch^48),ch=getchar();
return x*f;
}
int n,q,op;ll pw[N];
vector<pair<int,int> >mdf[N],Mdf[N];
int ord[N],pos[N];
int fa[N],siz[N],cnt[N];
__gnu_pbds::priority_queue<int>Q[N];
int find(int x){return fa[x]==x?x:fa[x]=find(fa[x]);}
int rt[N];struct node{int ls,rs,hsh;bool tg;}T[N*160];int tot;
int update(int pre,int L,int R,int l=1,int r=n){
int rt=++tot;T[rt]=T[pre];
if(L==l&&r==R){T[rt].tg^=1;T[rt].hsh=(pw[r-l+1]-1-T[rt].hsh+mod)%mod;return rt;}
int mid=(l+r)>>1;
if(R<=mid) T[rt].ls=update(T[rt].ls,L,R,l,mid);
else if(L>mid) T[rt].rs=update(T[rt].rs,L,R,mid+1,r);
else T[rt].ls=update(T[rt].ls,L,mid,l,mid),T[rt].rs=update(T[rt].rs,mid+1,R,mid+1,r);
T[rt].hsh=(T[T[rt].ls].hsh*pw[r-mid]+T[T[rt].rs].hsh)%mod;
if(T[rt].tg) T[rt].hsh=(pw[r-l+1]-1-T[rt].hsh+mod)%mod;
// Debug("%d %d %d\n",l,r,T[rt].hsh);
return rt;
}
bool cmp(int pu,int pv,int l=1,int r=n,bool tgu=0,bool tgv=0){
if(l==r) return (tgu^T[pu].hsh)<(tgv^T[pv].hsh);
int mid=(l+r)>>1,lu=T[pu].ls,lv=T[pv].ls;
tgu^=T[pu].tg,tgv^=T[pv].tg;
if(tgu==tgv?(T[lu].hsh==T[lv].hsh):(T[lu].hsh-pw[mid-l+1]+1+T[lv].hsh+mod)%mod==0)
return cmp(T[pu].rs,T[pv].rs,mid+1,r,tgu,tgv);
else return cmp(lu,lv,l,mid,tgu,tgv);
}
int Mn[N<<2][2],Mx[N<<2][2];bool rev[N<<2];
void pushup(int x){
Mn[x][0]=min(Mn[x<<1][0],Mn[x<<1|1][0]);
Mn[x][1]=min(Mn[x<<1][1],Mn[x<<1|1][1]);
Mx[x][0]=max(Mx[x<<1][0],Mx[x<<1|1][0]);
Mx[x][1]=max(Mx[x<<1][1],Mx[x<<1|1][1]);
}
void Build(int l=1,int r=n,int rt=1){
if(l==r){
Mn[rt][0]=Mx[rt][0]=pos[l];
Mn[rt][1]=inf,Mx[rt][1]=-inf;return;
}int mid=(l+r)>>1;
Build(l,mid,rt<<1);Build(mid+1,r,rt<<1|1);
pushup(rt);
}
void PutTag(int x){
rev[x]^=1;
swap(Mn[x][0],Mn[x][1]);
swap(Mx[x][0],Mx[x][1]);
}
void pushdown(int x){if(rev[x]) PutTag(x<<1),PutTag(x<<1|1),rev[x]=0;}
void Update(int L,int R,int l=1,int r=n,int rt=1){
if(L==l&&r==R) return PutTag(rt);
int mid=(l+r)>>1;pushdown(rt);
if(R<=mid) Update(L,R,l,mid,rt<<1);
else if(L>mid) Update(L,R,mid+1,r,rt<<1|1);
else Update(L,mid,l,mid,rt<<1),Update(mid+1,R,mid+1,r,rt<<1|1);
pushup(rt);
}
signed LJY(){
n=read();q=read();op=read();
pw[0]=1;For(i,1,n) pw[i]=pw[i-1]*B%mod;
For(i,1,q){
int l=read(),r=read(),u=read(),d=read();
mdf[l].emplace_back(u,d);
mdf[r+1].emplace_back(u,d);
Mdf[u].emplace_back(l,r);
Mdf[d+1].emplace_back(l,r);
}For(i,1,n){
rt[i]=rt[i-1];
for(auto [l,r] within mdf[i]) rt[i]=update(rt[i],l,r);
}For(i,1,n) ord[i]=i;
sort(ord+1,ord+1+n,[&](int x,int y){return cmp(rt[x],rt[y]);});
For(i,1,n) pos[ord[i]]=i;
For(i,1,n) fa[i]=i,siz[i]=1;Build();ll ans=0;
For(i,1,n){
ans+=n;for(auto [l,r] within Mdf[i]) Update(l,r);
int l=Mn[1][1],r=Mx[1][0];
if(l<=r){
int x=find(r);
ans+=max((ll)siz[x]*cnt[x]-1,0ll);
ans-=max((ll)siz[x]*(++cnt[x])-1,0ll);
while(x>l){
int nw=find(x-1);
ans+=max((ll)siz[x]*cnt[x]-1,0ll)+max((ll)siz[nw]*cnt[nw]-1,0ll);
fa[x]=nw;siz[nw]+=siz[x];cnt[nw]+=cnt[x];
while(!Q[x].empty()&&Q[x].top()>=nw) cnt[nw]++,Q[x].pop();
Q[nw].join(Q[x]);
ans-=max((ll)siz[nw]*cnt[nw]-1,0ll);x=nw;
}
}else if(1<=r&&l<=n){
int x=find(l);
if(x<=r){
ans+=max((ll)siz[x]*cnt[x]-1,0ll);
ans-=max((ll)siz[x]*(++cnt[x])-1,0ll);
}else Q[x].push(r);
}if(op||i==n) printf("%lld ",ans);
}return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Subtask #1:
score: 0
Wrong Answer
Test #1:
score: 5
Accepted
time: 0ms
memory: 24564kb
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: 5ms
memory: 24416kb
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: 0
Wrong Answer
time: 4ms
memory: 24768kb
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:
1
result:
wrong answer 1st numbers differ - expected: '5', found: '1'
Subtask #2:
score: 0
Wrong Answer
Test #4:
score: 10
Accepted
time: 92ms
memory: 103340kb
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: 0
Wrong Answer
time: 0ms
memory: 28532kb
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:
151
result:
wrong answer 1st numbers differ - expected: '2280', found: '151'
Subtask #3:
score: 0
Wrong Answer
Test #8:
score: 10
Accepted
time: 273ms
memory: 230860kb
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:
1
result:
ok 1 number(s): "1"
Test #9:
score: 10
Accepted
time: 92ms
memory: 96652kb
input:
5000 200000 0 4336 5000 1 1 686 5000 2 2 3130 5000 3 3 672 5000 4 4 1664 5000 5 5 1480 5000 6 6 1326 5000 7 7 3726 5000 8 8 4170 5000 9 9 4794 5000 10 10 3374 5000 11 11 1836 5000 12 12 310 5000 13 13 2146 5000 14 14 3266 5000 15 15 820 5000 16 16 1152 5000 17 17 2876 5000 18 18 134 5000 19 19 828 5...
output:
24995
result:
ok 1 number(s): "24995"
Test #10:
score: 10
Accepted
time: 74ms
memory: 98512kb
input:
5000 200000 0 1410 5000 1 1 3340 5000 2 2 4202 5000 3 3 4450 5000 4 4 914 5000 5 5 4514 5000 6 6 4 5000 7 7 238 5000 8 8 3182 5000 9 9 3302 5000 10 10 2136 5000 11 11 1504 5000 12 12 3204 5000 13 13 2078 5000 14 14 4026 5000 15 15 3690 5000 16 16 4430 5000 17 17 1304 5000 18 18 2156 5000 19 19 4154 ...
output:
10000
result:
ok 1 number(s): "10000"
Test #11:
score: 10
Accepted
time: 122ms
memory: 115556kb
input:
5000 200000 0 1556 3445 1 1 1803 3198 2 2 790 4211 3 3 564 4437 4 4 1128 3873 5 5 129 4872 6 6 2062 2939 7 7 1480 3521 8 8 1252 3749 9 9 942 4059 10 10 111 4890 11 11 915 4086 12 12 1575 3426 13 13 2186 2815 14 14 392 4609 15 15 1689 3312 16 16 492 4509 17 17 866 4135 18 18 381 4620 19 19 92 4909 20...
output:
34989
result:
ok 1 number(s): "34989"
Test #12:
score: 10
Accepted
time: 116ms
memory: 140372kb
input:
5000 200000 0 1 1 2330 2671 2 2 789 4212 3 3 1593 3408 4 4 438 4563 5 5 2048 2953 6 6 491 4510 7 7 578 4423 8 8 770 4231 9 9 482 4519 10 10 395 4606 11 11 1960 3041 12 12 1289 3712 13 13 621 4380 14 14 2235 2766 15 15 916 4085 16 16 781 4220 17 17 1440 3561 18 18 902 4099 19 19 1998 3003 20 20 641 4...
output:
49977
result:
ok 1 number(s): "49977"
Test #13:
score: 0
Wrong Answer
time: 219ms
memory: 198392kb
input:
5000 200000 0 1 661 1 2 1 1385 3 4 1 225 5 6 1 1833 7 8 1 58 9 10 1 2064 11 12 1 235 13 14 1 1918 15 16 1 2137 17 18 1 538 19 20 1 513 21 22 1 1405 23 24 1 1376 25 26 1 1711 27 28 1 165 29 30 1 209 31 32 1 68 33 34 1 1864 35 36 1 1455 37 38 1 425 39 40 1 669 41 42 1 2326 43 44 1 133 45 46 1 2257 47 ...
output:
1
result:
wrong answer 1st numbers differ - expected: '5001', found: '1'
Subtask #4:
score: 0
Wrong Answer
Test #14:
score: 0
Wrong Answer
time: 282ms
memory: 230692kb
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:
5000 2887 2050 913 491 433 211 49 55 51 56 61 66 71 76 81 86 91 96 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1...
result:
wrong answer 2nd numbers differ - expected: '5653', found: '2887'
Subtask #5:
score: 0
Wrong Answer
Test #21:
score: 0
Wrong Answer
time: 764ms
memory: 167260kb
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 233099 266197 299295 332393 365491 398589 598589 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:
wrong answer 2nd numbers differ - expected: '400000', found: '233099'
Subtask #6:
score: 0
Wrong Answer
Test #28:
score: 15
Accepted
time: 1335ms
memory: 345792kb
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:
400001
result:
ok 1 number(s): "400001"
Test #29:
score: 0
Wrong Answer
time: 823ms
memory: 205476kb
input:
200000 200000 0 1 1 56536 200000 2 2 132706 200000 3 3 82540 200000 4 4 109520 200000 5 5 142654 200000 6 6 101918 200000 7 7 106538 200000 8 8 159544 200000 9 9 26906 200000 10 10 188164 200000 11 11 191128 200000 12 12 67484 200000 13 13 85262 200000 14 14 60094 200000 15 15 97210 200000 16 16 732...
output:
39999127311
result:
wrong answer 1st numbers differ - expected: '39999163316', found: '39999127311'
Subtask #7:
score: 0
Wrong Answer
Test #37:
score: 0
Wrong Answer
time: 613ms
memory: 249716kb
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...
output:
100000 200000 195499 260665 271141 218275 174546 180577 96202 106891 31978 34885 32891 35421 20611 21985 23359 24733 26107 27481 28855 30229 31603 32977 34351 35725 37099 38473 39847 41221 42595 43969 45343 46717 48091 49465 50839 52213 53587 54961 56335 57709 59083 60457 52651 44529 38541 39361 401...
result:
wrong answer 6th numbers differ - expected: '281125', found: '218275'