QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#716993 | #9465. 基础 01 练习题 | maojun | 0 | 991ms | 350476kb | C++23 | 3.1kb | 2024-11-06 16:35:09 | 2024-11-06 16:35:12 |
Judging History
answer
#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/priority_queue.hpp>
using namespace std;bool Mbe;
namespace MAOJUN{
typedef long long ll;typedef pair<int,int> pi;
const int N=2e5+5;
int n,q,op,x1[N],x2[N],y1[N],y2[N];
int P[N],Q[N];
namespace T1{
typedef unsigned long long ull;
const int S=1.5e7;
int idx=0,rt[N],ls[S],rs[S],cv[S];ull vl[S],H[S];
#define md (l+r>>1)
#define Ls ls[p],l,md
#define Rs rs[p],md+1,r
void U(int&p,int l,int r,int L,int R){
int q=++idx;ls[q]=ls[p];rs[q]=rs[p];cv[q]=cv[p];H[q]=H[p];p=q;
if(L<=l&&r<=R){H[p]=H[p]^vl[r]^vl[l-1];cv[p]^=1;return;}
if(L<=md)U(Ls,L,R);if(R>md)U(Rs,L,R);H[p]=H[ls[p]]^H[rs[p]];
}
bool F(int p,int l,int r,int q,int tp,int tq){
if(l==r)return tp>tq;tp^=cv[p];tq^=cv[q];
return H[ls[p]]^H[ls[q]]^(tp^tq?vl[md]^vl[l-1]:0)?F(Rs,rs[q],tp,tq):F(Ls,ls[q],tp,tq);
}
vector<pi>vu[N];
inline void slv(){
for(int i=1;i<=q;i++){
vu[x1[i]].emplace_back(y1[i],y2[i]);
vu[x2[i]+1].emplace_back(y1[i],y2[i]);
}
mt19937_64 rnd(time(NULL));
for(int i=1;i<=n;i++)vl[i]=vl[i-1]^rnd();
for(int i=1;i<=n;i++){rt[i]=rt[i-1];for(auto[l,r]:vu[i])U(rt[i],1,n,l,r);}
iota(P+1,P+n+1,1);sort(P+1,P+n+1,[&](int x,int y){return F(rt[x],1,n,rt[y],0,0);});
for(int i=1;i<=n;i++)Q[P[i]]=i;
}
}
namespace T2{
const int S=N<<2;
int M,L[S][2],R[S][2],tg[S];
inline void P(int p){
for(int o:{0,1}){L[p][o]=min(L[p<<1][o],L[p<<1|1][o]);R[p][o]=max(R[p<<1][o],R[p<<1|1][o]);}
if(tg[p]){swap(L[p][0],L[p][1]);swap(R[p][0],R[p][1]);}
}
inline void C(int p){swap(L[p][0],L[p][1]);swap(R[p][0],R[p][1]);tg[p]^=1;}
vector<pi>vu[N];
inline void init(){
for(M=1;M<=n;M<<=1);memset(L,0x3f,sizeof L);
for(int i=1;i<=n;i++)L[M+i][0]=R[M+i][0]=Q[i];
for(int i=M;i;i--)P(i);
for(int i=1;i<=q;i++){
vu[y1[i]].emplace_back(x1[i],x2[i]);
vu[y2[i]+1].emplace_back(x1[i],x2[i]);
}
}
inline pi qry(int i){
for(auto[l,r]:vu[i]){
for(l+=M-1,r+=M+1;l^r^1;){if(~l&1)C(l^1);if(r&1)C(r^1);P(l>>=1);P(r>>=1);}
for(;l>>=1;P(l));
}
return pi(L[1][0],R[1][1]);
}
}
int s1[N],s2[N],fa[N];__gnu_pbds::priority_queue<int>pq[N];
int fd(int x){return x==fa[x]?x:fa[x]=fd(fa[x]);}
inline ll f(int x){return s2[x]?(ll)s1[x]*s2[x]-1:0;}
inline void main(){
scanf("%d%d%d",&n,&q,&op);
for(int i=1;i<=q;i++)scanf("%d%d%d%d",&x1[i],&x2[i],&y1[i],&y2[i]);
T1::slv();T2::init();
for(int i=1;i<=n;i++)s1[fa[i]=i]=1;
ll as=0;
for(int i=1;i<=n;i++){
auto[L,R]=T2::qry(i);
if(L<R){
int x=fd(R);as-=f(x);s2[x]++;
for(int y;x>L;x=y){
as-=f(y=fd(x-1));
fa[x]=y;s1[y]+=s1[x];s2[y]+=s2[x];pq[y].join(pq[x]);
while(!pq[y].empty()&&pq[y].top()>=y){s2[y]++;pq[y].pop();}
}
as+=f(x);
}else if(L<=n&&R){
int x=fd(L);
if(x<=R){as-=f(x);s2[x]++;as+=f(x);}
else pq[x].push(R);
}
if(op||i==n)printf("%lld ",(ll)i*n-as);
}
}
}bool Med;int main(){
#ifdef LOCAL
freopen("3.in","r",stdin);
freopen("data.out","w",stdout);
#endif
MAOJUN::main();
#ifdef LOCAL
fprintf(stderr,"%lfs\n",clock()/1000.);
fprintf(stderr,"%lfMB\n",(&Mbe-&Med)/1024./1024);
#endif
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: 2ms
memory: 21248kb
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: 2ms
memory: 21128kb
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: 0ms
memory: 27280kb
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: 96ms
memory: 122540kb
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: 25200kb
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: 247ms
memory: 273812kb
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: 0
Wrong Answer
time: 102ms
memory: 110740kb
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:
1
result:
wrong answer 1st numbers differ - expected: '24995', found: '1'
Subtask #4:
score: 0
Wrong Answer
Test #14:
score: 0
Wrong Answer
time: 233ms
memory: 275948kb
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:
8 9 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 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 1st numbers differ - expected: '5000', found: '8'
Subtask #5:
score: 0
Wrong Answer
Test #21:
score: 0
Wrong Answer
time: 400ms
memory: 205932kb
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 200070 200019 200028 200037 200016 200013 400013 400015 600015 800015 800017 1000017 1200017 1400017 1600017 1600019 1800019 2000019 2000021 2200021 2400021 2400023 2600023 2800023 3000023 3200023 3400023 3600023 3600025 3800025 4000025 4200025 4400025 4600025 4800025 4800027 5000027 5200027 ...
result:
wrong answer 2nd numbers differ - expected: '400000', found: '200070'
Subtask #6:
score: 0
Wrong Answer
Test #28:
score: 15
Accepted
time: 991ms
memory: 350476kb
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: 420ms
memory: 240984kb
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:
200001
result:
wrong answer 1st numbers differ - expected: '39999163316', found: '200001'
Subtask #7:
score: 0
Wrong Answer
Test #37:
score: 0
Wrong Answer
time: 468ms
memory: 298400kb
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:
12 23 34 45 56 67 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 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 1st numbers differ - expected: '100000', found: '12'