QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#93234 | #21566. 四维偏序 | sssmzy# | 50 | 692ms | 9460kb | C++14 | 3.0kb | 2023-03-31 15:21:29 | 2023-03-31 15:21:33 |
Judging History
answer
#include<bits/stdc++.h>
#define pii pair<int,int>
#define fi first
#define se second
#define dg(x) cerr<<"line: "<<__LINE__<<" "<<#x<<": "<<x<<endl
#define gc()(xS==xTT&&(xTT=(xS=xB)+fread(xB,1,1<<20,stdin),xS==xTT)?0:*xS++)
#define pc(x)(p3-obuf<1000000)?(*p3++=x):(fwrite(obuf,p3-obuf,1,stdout),p3=obuf,*p3++=x)
using namespace std;typedef long long ll;typedef double db;typedef long double ld;typedef unsigned long long ull;typedef unsigned int ui;char xch,xB[1<<20],*xS=xB,*xTT=xB,obuf[1000000],*p3=obuf;inline ll read(){char ch=gc();ll x=0,f=1;while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=gc();}while('0'<=ch&&ch<='9'){x=(x<<1)+(x<<3)+(ch^48);ch=gc();}return x*f;}static char cc[20];template<typename item>inline void pt( item x){ int len=0;if(!x)pc('0');if(x<0)x=-x,pc('-');while(x)cc[len++]=x%10+'0',x/=10;while(len--)pc(cc[len]);}inline void pS(string s){for(int i=0;i<s.length();i++)pc(s[i]);}inline ll read2(){char ch=gc();ll x=0,f=1;while(ch<'0'||ch>'1'){if(ch=='-')f=-1;ch=gc();}while('0'<=ch&&ch<='9'){x=(x<<1)+(ch^48);ch=gc();}return x*f;}inline __int128 iread(){char ch=gc();__int128 x=0,f=1;while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=gc();}while('0'<=ch&&ch<='9'){x=(x<<1)+(x<<3)+(ch^48);ch=gc();}return x*f;}
const int maxn=1e5+10;
int n,x[maxn],y[maxn],z[maxn],t[maxn];ll ans;
void cdq3(vector<pii>&ds)
{
if(ds.size()<2)return;
nth_element(ds.begin(),ds.begin()+(ds.size()-1>>1),ds.end(),[](pii A,pii B){return z[A.fi]<z[B.fi];});int mid=z[ds[ds.size()-1>>1].fi];
vector<pii>L((ds.size()-1>>1)+1),R(ds.size()-L.size());int p1=0,p2=0;for(auto &t:ds)if(z[t.fi]<=mid)L[p1++]=t;else R[p2++]=t;
cdq3(L),cdq3(R);
p1=0,p2=-1;int cnt=0;
for(;p1<R.size();p1++)
{
if(!R[p1].se)continue;
while(p2<(int)L.size()-1&&t[L[p2+1].fi]<t[R[p1].fi]){p2++;cnt+=!L[p2].se;}
ans+=cnt;
}
p1=p2=0;int p3=0;while(p1<L.size()&&p2<R.size())if(t[L[p1].fi]<t[R[p2].fi])ds[p3]=L[p1],p1++,p3++;else ds[p3]=R[p2],p2++,p3++;
while(p1<L.size())ds[p3]=L[p1],p1++,p3++;
while(p2<R.size())ds[p3]=R[p2],p2++,p3++;
}
void cdq2(vector<pii>&ds)
{
if(ds.size()<2)return;
nth_element(ds.begin(),ds.begin()+(ds.size()-1>>1),ds.end(),[](pii A,pii B){return y[A.fi]<y[B.fi];});int mid=y[ds[ds.size()-1>>1].fi];
vector<pii>L((ds.size()-1>>1)+1),R(ds.size()-L.size());int p1=0,p2=0,p3=0,c=0;for(auto t:ds)if(y[t.fi]<=mid){L[p1++]=t;if(!t.se)c++;}else {R[p2++]=t;if(t.se)c++;}
vector<pii>T(c);for(auto t:L)if(!t.se)T[p3++]=t;for(auto t:R)if(t.se)T[p3++]=t;
cdq3(T);cdq2(L),cdq2(R);
}
void cdq1(vector<pii>&ds,int l,int r)
{
if(l==r)return;
int mid=l+r>>1;
vector<pii>L(mid-l+1<<1),R(r-mid<<1),T(r-l+1);int p1=0,p2=0,p3=0;for(auto t:ds)if(x[t.fi]<=mid){L[p1++]=t;if(!t.se)T[p3++]=t;}else {R[p2++]=t;if(t.se)T[p3++]=t;}
cdq2(T);cdq1(L,l,mid),cdq1(R,mid+1,r);
}
signed main()
{
n=read();
for(int i=1;i<=n;i++)x[i]=read(),y[i]=read(),z[i]=read(),t[i]=read();
vector<pii>ps;for(int i=1;i<=n;i++)ps.push_back({i,0}),ps.push_back({i,1});
cdq1(ps,1,n);
pt(ans);
fwrite(obuf,p3-obuf,1,stdout);
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 10
Accepted
time: 678ms
memory: 9008kb
input:
49995 25201 24841 32082 47399 11858 35036 36484 24573 28368 8935 35040 10246 23421 18221 28778 25594 13980 42394 47584 47243 9732 29095 25460 10151 36904 19647 24412 16243 10069 16471 20628 8669 47214 43247 23698 49530 42218 37968 26068 35481 48927 45376 10770 26532 48097 11865 4913 25311 6412 16257...
output:
188938349
result:
ok single line: '188938349'
Test #2:
score: 10
Accepted
time: 692ms
memory: 9460kb
input:
49997 39191 24440 33693 28479 41996 32707 47350 3311 30285 44451 7461 38543 40380 45414 4751 19900 31957 37065 24909 40388 48485 10004 31386 24932 8200 23527 39784 20642 48507 35443 48730 10164 42593 643 44221 14678 25759 32952 36341 32665 21052 2385 15155 44041 33862 31281 31847 28304 38034 32573 3...
output:
187908530
result:
ok single line: '187908530'
Test #3:
score: 10
Accepted
time: 672ms
memory: 9388kb
input:
49993 15704 40275 28199 37576 11636 23979 39224 42558 30195 49051 14472 41954 30757 1106 48320 28027 12818 44627 5050 35972 16825 29649 1978 37838 48347 36342 34654 37324 47144 26121 25980 39370 15029 22038 43108 44296 45405 36989 27455 36048 35069 32406 29158 23754 8626 32340 30765 24803 14709 4719...
output:
187391225
result:
ok single line: '187391225'
Test #4:
score: 10
Accepted
time: 674ms
memory: 9148kb
input:
49995 47120 12943 38136 14837 38570 28835 36055 30539 47574 26942 12879 23038 33124 8358 8818 17659 39442 49141 42952 7178 43709 49774 39916 25962 45195 11192 34831 10205 38617 41991 15702 48060 40193 36820 5097 32505 48504 38804 49449 16509 30019 19370 48801 36256 26166 34505 6035 45587 45140 32176...
output:
188643952
result:
ok single line: '188643952'
Test #5:
score: 10
Accepted
time: 671ms
memory: 9440kb
input:
49997 12981 34193 43546 30038 12385 26386 14914 10769 38576 28536 29531 41028 38886 26895 41350 24943 37840 36113 23276 28552 32521 12500 26345 26098 8583 27277 27193 21987 47140 34380 29909 16596 32275 2429 45729 38029 43119 41980 29028 18002 31598 48409 28149 45671 29131 37221 40298 47662 42088 29...
output:
189511997
result:
ok single line: '189511997'
Test #6:
score: 0
Time Limit Exceeded
input:
99995 74835 97387 39179 33679 85030 36478 82691 53293 28368 60234 94435 88525 68215 28772 95398 69882 92388 97231 87049 90370 79089 60139 48473 32699 36904 18772 73511 70624 66465 28536 85427 51624 93241 99518 42581 64660 87962 85469 82936 82647 95370 76520 14432 94023 61859 75299 33850 70932 66251 ...
output:
result:
Test #7:
score: 0
Time Limit Exceeded
input:
99992 90251 87545 62907 38103 71466 92527 78799 36022 99027 91923 73231 72803 1855 77996 33094 67620 94603 85941 99105 57139 79625 87807 99738 75923 86318 87293 61156 34798 76097 89339 91955 98021 72014 94265 86784 82466 86965 86017 88768 66470 82382 73723 68235 86217 82316 74772 84469 95548 97167 8...
output:
result:
Test #8:
score: 0
Time Limit Exceeded
input:
99994 84153 71558 79019 82707 76346 14877 99937 57295 78496 90987 46483 81919 52697 74902 78707 12498 86073 27723 99406 87853 32485 76057 46713 39996 53270 71946 73538 26099 84340 66555 57692 29368 25984 87988 77952 21691 91940 67377 91211 76523 98369 95630 93021 86644 87181 97621 54310 54683 79891 ...
output:
result:
Test #9:
score: 0
Time Limit Exceeded
input:
99997 91687 96540 97158 4337 87660 16364 23596 98356 90574 38284 36545 70969 39122 63052 58092 49390 97611 94875 91161 20876 97397 89674 91128 53918 71814 71773 91969 95858 30271 80365 57931 90529 94571 97532 72050 83937 23363 87395 99412 81922 28530 69593 84988 95532 54466 54614 62210 71213 84779 8...
output:
result:
Test #10:
score: 0
Time Limit Exceeded
input:
99991 68618 96111 78352 52543 77189 66020 29990 98377 84523 99409 39471 97281 73251 90624 14746 70252 65227 86828 9641 69720 87552 7915 98953 55794 78937 23325 77330 92393 1284 76664 65953 95158 92860 95396 42615 7191 28564 93668 96153 50707 62620 30083 88670 39757 32744 44380 84802 98233 83306 1204...