QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#258640 | #6304. Rectangle | Crying | TL | 4668ms | 108896kb | C++17 | 6.1kb | 2023-11-19 21:58:51 | 2023-11-19 21:58:52 |
Judging History
answer
#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops")
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=(a);i<=(b);i++)
#define per(i,a,b) for(int i=(a);i>=(b);i--)
#define op(x) ((x&1)?x+1:x-1)
#define odd(x) (x&1)
#define even(x) (!odd(x))
#define lc(x) (x<<1)
#define rc(x) (lc(x)|1)
#define lowbit(x) (x&-x)
#define mp(x,y) make_pair(x,y)
typedef long long ll;
typedef __int128 i128;
typedef unsigned long long ull;
typedef double db;
using namespace std;
const ll MAXN = 2e5+10,M = 1e9,mod = 998244353;
typedef array<ll,2> pr;
typedef array<ll,4> node;
void tomin(ll& x,ll y){x = min(x,y);}
void tomax(ll& x,ll y){x = max(x,y);}
void add(ll& x,ll y){x=(x+y)%mod;}
void sub(ll& x,ll y){x=(x-y+mod)%mod;}
ll addv(ll x,ll y){return (x+y)%mod;}
ll subv(ll x,ll y){return (x-y+mod)%mod;}
struct D{
int b[MAXN],tot;
void clr(){tot=0;}
void add(int x){b[++tot]=x;}
void pr(){
sort(b+1,b+1+tot);
tot=unique(b+1,b+1+tot)-b-1;
b[tot+1]=M+1;
}
int qry(int x){return lower_bound(b+1,b+1+tot,x)-b;}
}dx,dy;
int T,n;
ll ans;
pr a[MAXN],b[MAXN],ra[MAXN],rb[MAXN]; //左下,右上
ll C(int x,int y){
if(x<y)return 0;
i128 r = 1;
rep(i,0,y-1)r = r*(x-i);
if(y==2)r/=2;
else if(y==3)r/=6;
return r%mod;
}
namespace _{
ll dp[4][MAXN],sum[4][MAXN],pre[MAXN],vx[MAXN],vy[MAXN];
ll spre[MAXN],all,ban;
#define mid ((l+r)>>1)
struct Seg{
ll tag[MAXN<<2],sum[MAXN<<2],val[MAXN<<2],all[MAXN<<2];
vector<node> opt;
void pu(int x){
opt.push_back({tag[x],sum[x],val[x],x});
sum[x]=sum[lc(x)]+sum[rc(x)],val[x]=val[rc(x)];
}
void cv(int x,ll v){
opt.push_back({tag[x],sum[x],val[x],x});
tag[x]=v,sum[x]=all[x]*v,val[x]=v;
}
void pd(int x){
if(tag[x]==-1)return;
opt.push_back({tag[x],sum[x],val[x],x});
cv(lc(x),tag[x]),cv(rc(x),tag[x]);
tag[x]=-1;
}
//
void build(int x,int l,int r,int t){
tag[x]=-1; all[x] = 0;
if(l==r){
val[x]=(!t)?(dx.b[l+1]):(M+1);
sum[x]=val[x]*vx[l];
all[x]=vx[l];
return;
}
build(lc(x),l,mid,t),build(rc(x),mid+1,r,t);
pu(x);
all[x]=all[lc(x)]+all[rc(x)];
}
void mdf(int x,int l,int r,int ql,int qr,ll val){
if(ql>qr)return;if(ql<=l && qr>=r)return cv(x,val);
pd(x);
if(ql<=mid)mdf(lc(x),l,mid,ql,qr,val);
if(qr>mid)mdf(rc(x),mid+1,r,ql,qr,val);
pu(x);
}
int qry(int x,int l,int r,ll lim){ //第一个>=lim的位置
if(val[x]<lim)return r+1;
if(l==r)return r;
pd(x);
int ret=qry(lc(x),l,mid,lim);if(ret != mid+1)return ret;
return qry(rc(x),mid+1,r,lim);
}
ll qsum(int x,int l,int r,int ql,int qr){
if(ql>qr)return 0;if(ql<=l && qr>=r)return sum[x];
pd(x);ll ret=0;
if(ql<=mid)ret+=qsum(lc(x),l,mid,ql,qr);
if(qr>mid)ret+=qsum(rc(x),mid+1,r,ql,qr);
return ret;
}
//
void Init(int t){
opt.clear();
build(1,1,dx.tot,t);
}
void cmax(int l,int r,ll t){
if(l>r)return;
int q=qry(1,1,dx.tot,t);
mdf(1,1,dx.tot,l,q-1,t);
}
void cmin(int l,int r,ll t){
if(l>r)return;
int q=qry(1,1,dx.tot,t);
mdf(1,1,dx.tot,q,r,t);
}
void back(){
assert(opt.size());
node nd=opt.back();opt.pop_back(); int x=nd[3];
tag[x]=nd[0],sum[x]=nd[1],val[x]=nd[2];
}
void back(int to){
assert(opt.size()>=to);
while(opt.size()>to)back();
}
}sL,sR;
vector<pr>o[MAXN<<2];
void build(int x,int l,int r){
o[x].clear();if(l==r)return;
build(lc(x),l,mid),build(rc(x),mid+1,r);
}
void ins(int x,int l,int r,int ql,int qr,pr p){
if(ql>qr)return;if(ql<=l && qr>=r)return (void)(o[x].push_back(p));
if(ql<=mid)ins(lc(x),l,mid,ql,qr,p);
if(qr>mid)ins(rc(x),mid+1,r,ql,qr,p);
}
void mdf(int l,int r,int L,int R){
if(l>r)return;
all++;
sL.cmax(l,r,L); sR.cmax(l,r,L);
sR.cmin(l,r,R); sL.cmin(l,r,R);
}
ll qry(){
return sR.qsum(1,1,dx.tot,1,ban) - sL.qsum(1,1,dx.tot,1,ban);
}
void solve(int x,int l,int r,ll xl,ll xr){
int tagL=sL.opt.size(),tagR=sR.opt.size(),preban = ban;
for(auto [L,R] : o[x]){
tomax(xl,L),tomin(xr,R);
ban = min(ban,R);
mdf(1,L-1,dx.b[L],dx.b[R+1]);
}
if(l^r){
solve(lc(x),l,mid,xl,xr);
solve(rc(x),mid+1,r,xl,xr);
}else{
ll ret = qry();
if(xl<=xr)ret += spre[xr]-spre[xl-1];
ret%=mod;
add(ans,ret * vy[l]);
}
sL.back(tagL),sR.back(tagR);ban = preban;
}
#undef mid
void solve(int tag){
dx.clr();dy.clr();
dx.add(1),dy.add(1);
rep(i,1,n){
dx.add(a[i][0]);
if(b[i][0]<M)dx.add(b[i][0]+1);
dy.add(a[i][1]);
if(b[i][1]<M)dy.add(b[i][1]+1);
}
dx.pr();dy.pr();
rep(i,1,dx.tot)vx[i]=dx.b[i+1]-dx.b[i];
rep(i,1,dy.tot)vy[i]=dy.b[i+1]-dy.b[i];
rep(i,1,n){
ra[i][0] = dx.qry(a[i][0]);
ra[i][1] = dy.qry(a[i][1]);
rb[i][0] = dx.qry(b[i][0]+1)-1;
rb[i][1] = dy.qry(b[i][1]+1)-1;
}
//三个x
ll mnR = dx.tot+1,mxL = 0;
rep(i,0,dx.tot)pre[i]=1;
rep(i,1,n){
tomax(pre[rb[i][0]],ra[i][0]);
tomin(mnR,rb[i][0]);
tomax(mxL,ra[i][0]);
}
pre[0]=1,spre[0]=0;
rep(i,1,dx.tot){
pre[i] = max(pre[i-1],pre[i]);
spre[i] = spre[i-1] + C(vx[i],2);
}
rep(i,0,dx.tot)rep(j,0,3)dp[j][i] = sum[j][i] = 0;
rep(i,1,dx.tot){
rep(j,1,3){
ll& ret=dp[j][i];
if(mnR>=i)add(ret,C(vx[i],j));
rep(k,1,j-1){
ll pos=pre[i-1]; //[pos,i-1]
if(pos<=i-1){
ll R=subv(sum[k][i-1],sum[k][pos-1]);
add(ret,R*C(vx[i],j-k));
}
}
if(mxL<=i && j==3)add(ans,ret);
sum[j][i] = addv(sum[j][i-1],ret);
}
}
//两个x,一个y
sL.Init(0),sR.Init(1);
build(1,1,dy.tot);
rep(i,1,n){
pr p={ra[i][0],rb[i][0]};
ins(1,1,dy.tot,1,ra[i][1]-1,p);
ins(1,1,dy.tot,rb[i][1]+1,dy.tot,p);
}
ban = dx.tot;
solve(1,1,dy.tot,1,dx.tot);
}
};
void solve(){
cin>>n;ans=0;
rep(i,1,n){
cin>>a[i][0]>>a[i][1]>>b[i][0]>>b[i][1];
}
//
_::solve(0);
rep(i,1,n)swap(a[i][0],a[i][1]),swap(b[i][0],b[i][1]);
_::solve(1);
//
cout<<ans<<"\n";
}
int main(){
ios::sync_with_stdio(false);cin.tie(0);
cin>>T;
while(T--)solve();
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 11ms
memory: 65696kb
input:
3 1 1 1 1000000000 1000000000 3 1 1 2 2 3 3 4 4 5 5 6 6 5 581574116 47617804 999010750 826131769 223840663 366320907 613364068 926991396 267630832 51913575 488301124 223957497 217461197 492085159 999485867 913732845 28144453 603781668 912516656 993160442
output:
230616300 64 977066618
result:
ok 3 number(s): "230616300 64 977066618"
Test #2:
score: 0
Accepted
time: 11ms
memory: 67156kb
input:
1000 10 5 7 6 10 4 3 6 9 1 6 3 7 1 1 7 10 1 2 7 7 5 2 8 3 2 1 5 7 1 1 10 6 1 7 2 8 4 7 5 9 10 6 6 8 10 4 4 9 9 2 4 6 5 5 3 10 10 1 3 4 4 2 2 3 6 7 5 8 6 2 7 8 8 5 7 10 10 2 4 7 8 10 3 6 6 10 1 2 7 4 7 5 10 9 4 5 8 9 2 7 5 9 2 2 9 7 3 3 8 4 1 1 8 6 5 4 10 6 3 9 7 10 10 3 1 8 9 1 3 8 10 4 1 7 4 2 4 5 ...
output:
28090346 21067815 91293528 63203269 14045217 24579047 49158123 56180656 10533942 83 28090372 101827338 512901428 38624242 10533932 42135595 7022614 7022661 7022622 31601641 21067817 35112979 7022628 7022682 17556485 42135554 59692019 28090452 14045202 73737099 42135505 31601703 49158091 28090434 108...
result:
ok 1000 numbers
Test #3:
score: 0
Accepted
time: 32ms
memory: 66072kb
input:
1000 10 56 6 85 86 2 67 79 76 41 32 57 94 7 24 95 72 4 82 98 99 21 16 64 95 5 15 97 50 75 34 93 63 65 1 74 40 62 50 91 57 10 1 66 4 99 73 28 80 35 9 46 84 72 57 12 74 75 24 20 72 86 30 35 51 52 20 32 80 48 1 27 38 38 79 30 91 86 49 11 78 31 10 84 36 95 84 18 76 83 96 87 6 97 24 59 74 79 81 36 6 49 1...
output:
286940182 6719 3879 10985 284425706 1482 154507014 337096188 15634 15198 13957 311811545 2065 487051821 104322525 4160 6232 3566 259869863 676660625 533734216 1108 210694302 941064564 9524057 366655439 960 712817222 294969344 505637269 5277 216 807601960 6489 192 252834684 9863 523061934 1036 370 16...
result:
ok 1000 numbers
Test #4:
score: 0
Accepted
time: 32ms
memory: 66588kb
input:
1000 10 151949335 343818689 226887829 843487881 26268786 629172470 727820988 753588469 239557045 129989050 828912527 803511337 216216272 737211068 952614934 901139965 9412307 270208240 969836975 781270622 210767204 691143582 734743967 978765608 115072779 149374200 365237395 723260248 373039270 50881...
output:
989992685 889170389 199600526 811602467 101647877 422274637 988817681 775346897 987827054 201664770 0 425324155 654779513 129937888 504567840 567363794 953468940 390846625 863893486 832900735 549488122 626520957 651708706 325695215 265584217 535054615 654784437 835844534 970196650 259827660 73563096...
result:
ok 1000 numbers
Test #5:
score: 0
Accepted
time: 582ms
memory: 66068kb
input:
20000 10 387518709 362080654 857718988 413892967 259574026 383071239 349422952 406322216 252781835 421214199 960954668 766986966 709548059 152868851 829506776 286195984 533564379 238783143 835360470 804665480 37715197 439312193 350269160 510361284 760325088 379134217 996444460 640572941 75706031 242...
output:
425031005 145199488 76594243 608094392 105901554 767793557 925027675 718008576 542146803 257776847 83948409 557131094 957234323 316994452 711146361 878596101 863265391 86278462 882556696 943381219 171834801 312110039 509815322 995001589 267270543 321796762 646607323 535110629 612892338 264981338 862...
result:
ok 20000 numbers
Test #6:
score: 0
Accepted
time: 505ms
memory: 66928kb
input:
20000 9 23397362 5465077 922916650 905326448 334129892 259574026 806023297 349422952 85390000 14589070 252781835 159363469 518493829 9904109 881263301 763351170 376515120 592421912 709548059 922381128 522936 888125869 919020884 968891551 192627293 528719402 238783143 846674462 269993278 155196111 41...
output:
38446691 441652008 80634077 86958519 313123987 37147655 292453230 135822548 347213034 875178269 572593450 121333363 910761745 288628833 144542647 336001702 492148086 504465362 307137735 40715447 936972207 895075762 698856636 442121431 960601688 728799681 619152060 51416671 586371383 183976942 996194...
result:
ok 20000 numbers
Test #7:
score: 0
Accepted
time: 1185ms
memory: 66884kb
input:
2000 98 441828066 355550044 980140398 758338808 139187839 379489833 732496729 915149220 6198442 7406064 811667085 671521385 634108502 54340068 750182168 712125681 51518185 164417838 414217749 690302726 26971686 349814847 96913121 613904116 18885592 344395345 969337141 761958781 6500321 288362602 695...
output:
847505316 69861689 762022665 942187496 610542723 297361682 408287130 37288980 129194998 781348133 138625309 885806848 596340815 251557403 136654463 415973838 348935020 217451841 607735223 183258123 453186006 29511771 486730947 90933161 744360742 932334149 464917933 58351031 36268611 777434481 348682...
result:
ok 2000 numbers
Test #8:
score: 0
Accepted
time: 2340ms
memory: 70572kb
input:
200 993 336152525 31049117 970839548 34483370 257968529 73378100 760295564 459870661 769587893 565770848 979251259 884779692 92706327 715631888 976631772 730467480 102936760 674056008 996888200 756831534 141490448 466112222 761954523 960644829 601216664 500053814 974949771 928192751 298296452 359164...
output:
163043779 101789580 214159985 605122084 222495872 595662571 919415389 27790333 940923361 745272650 432367810 269413997 881525570 275197159 128519736 759744770 394059985 858394070 885939030 507707772 380648232 853123251 659897376 142847962 866652391 78179639 672081467 655879491 267275050 880872481 74...
result:
ok 200 numbers
Test #9:
score: 0
Accepted
time: 161ms
memory: 67524kb
input:
200 989 1 8 5 9 6 4 9 7 9 4 10 10 3 3 8 7 7 1 9 5 9 4 10 6 4 3 7 8 3 1 7 4 2 5 3 6 3 4 4 7 4 3 7 9 1 2 9 8 4 3 6 4 2 2 6 10 6 8 7 10 2 1 3 9 1 1 4 10 1 5 4 8 2 3 4 9 4 3 9 9 1 2 6 7 7 4 9 5 4 3 8 10 4 1 8 10 7 2 8 5 2 4 3 8 5 4 10 6 9 1 10 5 5 3 7 7 6 4 10 10 6 6 7 9 1 1 3 10 2 2 9 8 2 3 7 8 3 9 10 ...
output:
3 1 2 1 2 1 2 3511294 1 3511294 2 2 3511295 3 2 2 6 1 2 1 1 3 1 3511294 1 1 10533874 1 1 1 2 2 1 6 432141794 1 1 2 4 1 3511294 2 3511294 3 3 1 2 1 853749714 3 3 7022585 3511294 2 2 3 7022585 3 14045164 1 2 1 1 1 4 2 4 3511295 3 3 3511295 3511295 7022585 1 2 1 3 2 1 7022585 2 2 2 3 2 7022585 2 4 3 2 ...
result:
ok 200 numbers
Test #10:
score: 0
Accepted
time: 682ms
memory: 67324kb
input:
200 993 5 48 42 78 55 33 66 92 6 5 38 34 38 34 82 48 9 76 34 86 50 39 72 44 46 54 96 82 4 13 68 24 39 25 93 56 36 53 98 86 19 10 73 24 54 27 97 84 34 21 93 76 44 7 70 89 63 73 97 98 50 24 94 35 8 30 98 67 3 15 81 67 39 9 78 24 8 65 100 98 13 5 86 33 54 67 99 84 3 2 43 4 53 51 70 86 1 61 61 90 46 78 ...
output:
1 1 2 1 2 3 2 1 2 1 1 1 1 1 2 2 1 2 2 17 1 3 1 10 1 2 2 1 1 81 15 1 170 1 4 1 2 1 1 2 1 2 1 2 1 1 4 1 2 1 2 1 1 1 1 2 3511413 1 2 1 2 2 7022597 1 2 2 2 2 2 1 1 1 1 2 1 1 2 1 1 1 1 1 1 3 2 4 1 2 3 1 6 1 1 1 2 1 1 1 1 2 10 6 5 1 1 1 1 1 1 2 10 6 2 4 3 3511332 2 2 1 1 1 4 1 2 1 2 1 5 7 6 1 1 2 1 1 1 1 ...
result:
ok 200 numbers
Test #11:
score: 0
Accepted
time: 4668ms
memory: 108896kb
input:
20 9956 444627993 347200064 774678572 839098978 96936514 121569633 839637347 729127099 343857875 554213034 875416430 628610537 15566043 187047055 405963021 764745923 487340755 59747358 604299543 832826844 486772462 67273090 826002755 268527861 703758831 112254125 887710074 874858855 569284980 830139...
output:
723891885 824191538 424987081 659035365 778857924 125675099 919713447 291966121 841813 399938856 822967409 178787426 958377822 295302425 835192235 569958073 114037901 814150865 893384876 929070768
result:
ok 20 numbers
Test #12:
score: -100
Time Limit Exceeded
input:
2 99774 247800693 19906287 955213467 53123614 752909581 205074868 772413424 686934334 565298662 150234672 941079197 750300220 29485217 794172007 678447605 874228231 524081254 14156413 775198532 256753797 121163010 271762780 489047491 996802646 61272893 135510320 459683721 975698463 37577668 16804082...