QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#382842 | #7436. Optimal Ordered Problem Solver | marher | 40 | 1973ms | 225116kb | C++17 | 5.3kb | 2024-04-08 19:42:32 | 2024-04-08 19:42:34 |
Judging History
answer
#pragma GCC optimize("Ofast","inline")
#include<bits/stdc++.h>
using namespace std;
const int N=2e6+200;
namespace IO {
#define iL (1 << 20)
char ibuf[iL], *iS = ibuf + iL, *iT = ibuf + iL;
#define gc() ((iS == iT) ? (iT = (iS = ibuf) + fread(ibuf, 1, iL, stdin), iS == iT ? EOF : *iS ++) : *iS ++)
template<class T> inline void read(T &x) {
x = 0;int f = 0;char ch = gc();
for (; !isdigit(ch); f |= ch == '-', ch = gc());
for (; isdigit(ch); x = (x << 1) + (x << 3) + (ch ^ 48), ch = gc());
x = (f == 1 ? ~ x + 1 : x);
}
template<class T, class... Args> inline void read(T &x, Args&... args) { read(x), read(args...); }
template<class T> inline void readch(T &x) { char ch = gc(); for (; !isalpha(ch); ch = gc()); x = ch; }
char Out[iL], *iter = Out;
#define flush() fwrite(Out, 1, iter - Out, stdout), iter = Out
template<class T> inline void write(T x, char ch = '\n') {
T l, c[35];
if (x < 0) *iter ++ = '-', x = ~ x + 1;
for (l = 0; !l || x; c[l] = x % 10, l++, x /= 10);
for (; l; -- l, *iter ++ = c[l] + '0');*iter ++ = ch;
flush();
}
template<class T, class... Args> inline void write(T x, Args... args) { write(x, ' '), write(args...); }
} // IO
using namespace IO;
struct poi
{
int x,y;
friend bool operator<(poi a,poi b)
{
return a.y==b.y?a.x>b.x:a.y<b.y;
}
int in(poi t)
{
return (t.x>=x)&(t.y>=y);
}
}a[N];
bool cmp(poi a,poi b)
{
return a.y==b.y?a.x>=b.x:a.y<b.y;
}
struct node
{
poi w,la;int opt,siz,rd;
void mk(poi d,int o)
{
if(o&1)opt|=1,w.y=la.y=d.y;
if(o&2)opt|=2,w.x=la.x=d.x;
}
}t[N<<2];
int n,m,pos[N],vis[N],ans[N],mx[N],ch[N<<1][2],tot,ro,now,nw[N],c;
int *g[N];
#define ls ch[x][0]
#define rs ch[x][1]
void up(int x)
{
t[x].siz=t[ls].siz+t[rs].siz+1;
}
int make_new(poi w)
{
int x=++tot;
t[x]=(node){w,(poi){},0,1,rand()%10000000};
return x;
}
void down(int x)
{
if(!t[x].opt)return;
if(ls)t[ls].mk(t[x].la,t[x].opt);
if(rs)t[rs].mk(t[x].la,t[x].opt);
t[x].opt=0;
}
void split(int x,poi k,int&a,int&b)
{
if(!x)a=b=0;
else
{
down(x);
if(cmp(k,t[x].w))a=x,split(rs,k,rs,b);
else b=x,split(ls,k,a,ls);
up(x);
}
}
int merge(int a,int b)
{
if(!a||!b)return a+b;
int w;
if(t[a].rd<t[b].rd)ch[a][1]=merge(ch[a][1],b),up(a),w=a;
else ch[b][0]=merge(a,ch[b][0]),up(b),w=b;
return w;
}
void dfs(int x,poi d,int opt)
{
if(!x)return;
down(x);
if(t[x].w.in(d)){if(opt==1)t[x].w.y=d.y;else t[x].w.x=d.x;dfs(ls,d,opt);dfs(rs,d,opt);}
else if(t[x].w.x<=d.x)dfs(rs,d,opt);
else if(t[x].w.y<=d.y)dfs(ls,d,opt);
up(x);
}
int find(int x,poi d)
{
if(!x)return 0;down(x);
if(t[x].w.in(d))return 1+find(ls,d)+find(rs,d);
if(t[x].w.x<=d.x)return find(rs,d);
if(t[x].w.y<=d.y)return find(ls,d);
return 0;
}
void insert(int d,int x)
{
for(int i=d;i<=n;i+=(i&(-i)))g[i][nw[i]++]=x;
}
void rinsert(int x,int y)
{
x=n-x+1;
for(int i=x;i<=n;i+=(i&(-i)))mx[i]=max(mx[i],y);
}
int rfind(int x)
{
x=n-x+1;int ans=0;if(x<0)return 0;
for(int i=x;i;i-=(i&(-i)))ans=max(ans,mx[i]);
return ans;
}
struct tree
{
int p[N];
void insert(int x,int d)
{
for(int i=x;i<=n;i+=(i&(-i)))p[i]+=d;
}
int find(int x)
{
int ans=0;
for(int i=x;i;i-=(i&(-i)))ans+=p[i];
return ans;
}
}xx,yy,pp;
poi st[N];int rr[N],tim;
void add(int x,int y,int opt)
{
rinsert(x,y);dfs(ro,(poi){x,y},opt);
int top=0,bg=clock();
for(int i=x;i;i-=(i&(-i)))
{
int&d=pos[i];int w;
while(d<nw[i]&&a[(w=g[i][d])].y<=y)
{
if(vis[w]){d++;continue;}
vis[w]=1;poi r=a[w];
xx.insert(r.x,-1),yy.insert(r.y,-1);
if(opt==1)r.y=y;else r.x=x;
st[++top]=r;d++;--now;
}
}
tim+=clock()-bg;
sort(st+1,st+1+top);
rr[top]=ro;
for(int i=top;i>=1;i--)split(rr[i],st[i],rr[i],rr[i-1]);
for(int i=top;i>=1;i--)rr[i-1]=merge(merge(rr[i],make_new(st[i])),rr[i-1]);
ro=rr[0];
}
vector<pair<int,int>>ask[N];
int main()
{
srand(19260817);
// freopen("in","r",stdin);
// freopen("out","w",stdout);
read(n,m);
// n=m=1e6;
now=n;
for(int i=1;i<=n;i++)
{
read(a[i].x,a[i].y);
// a[i].x=rand()%n+1;a[i].y=rand()%n+1;
xx.insert(a[i].x,1),yy.insert(a[i].y,1);
}
sort(a+1,a+1+n);
for(int i=1;i<=n;i++)g[i]=new int[xx.p[i]+2];
for(int i=1;i<=n;i++)insert(a[i].x,i);
// cerr<<1.0*clock()/CLOCKS_PER_SEC<<'\n';
for(int i=1,x=1e5,y=1e5;i<=m;i++)
{
int opt,X,Y;
read(opt,x,y,X,Y);
// opt=rand()%2+1,X=rand()%n+1,Y=rand()%n+1;x=rand()%n+1;y=rand()%n+1;
add(x,y,opt);if(rfind(X+1)>Y)continue;
ans[i]=find(ro,(poi){X,Y})+xx.find(X)+yy.find(Y)-now;
ask[Y].push_back(make_pair(X,i));
}
// cout<<1.0*tim/CLOCKS_PER_SEC<<'\n';
// return 0;
for(int i=n,pos=n;i>=1;i--)
{
for(auto x:ask[i])ans[x.second]+=pp.find(n-x.first);
while(pos&&a[pos].y==i)pp.insert(n-a[pos].x+1,1),pos--;
}
for(int i=1;i<=m;i++)write(ans[i]);
cerr<<1.0*clock()/CLOCKS_PER_SEC<<'\n';
}
Details
Tip: Click on the bar to expand more detailed information
Subtask #1:
score: 20
Accepted
Test #1:
score: 20
Accepted
time: 16ms
memory: 70896kb
input:
995 996 950 481 376 18 141 776 711 966 130 727 468 529 47 39 857 563 832 821 776 472 154 914 825 279 332 415 470 361 968 440 45 560 299 755 703 785 744 387 547 382 3 549 344 573 778 424 784 765 280 115 251 434 695 98 463 506 379 38 610 486 305 623 703 244 856 365 117 360 772 847 331 723 663 991 900 ...
output:
423 473 758 313 694 232 333 784 821 154 247 244 504 54 200 370 872 782 734 174 660 467 76 754 77 3 144 974 526 415 439 694 507 577 258 120 243 3 2 319 313 498 218 828 433 623 981 700 120 55 70 499 375 283 387 128 317 139 220 410 22 547 3 385 430 168 32 0 178 625 677 561 488 672 577 64 144 537 235 54...
result:
ok 996 numbers
Test #2:
score: 0
Accepted
time: 11ms
memory: 70764kb
input:
1000 998 483 753 603 464 306 515 71 717 536 195 335 816 275 223 236 392 764 856 434 203 910 542 595 408 185 212 559 836 27 238 959 252 830 212 946 431 794 63 164 800 566 307 861 840 555 580 37 225 976 897 946 891 459 163 101 679 511 141 628 271 115 202 6 911 131 99 991 975 578 60 193 889 683 437 408...
output:
411 275 9 632 553 5 873 494 172 893 41 194 638 599 747 37 653 919 560 334 536 26 244 448 800 189 64 383 829 662 4 196 785 548 215 430 258 463 132 488 581 217 229 513 765 817 750 3 213 1 624 545 499 79 59 873 211 334 709 371 597 290 0 957 689 192 119 6 322 390 129 464 24 278 876 824 243 663 443 84 61...
result:
ok 998 numbers
Test #3:
score: 0
Accepted
time: 8ms
memory: 70500kb
input:
1000 995 301 895 261 325 211 404 100 381 849 291 851 65 272 465 786 647 26 15 779 368 356 74 26 196 308 809 532 229 643 707 426 380 152 371 622 652 905 793 847 322 574 197 117 960 339 751 246 87 322 948 511 800 967 25 36 906 278 611 586 991 392 314 933 644 42 569 948 769 982 134 518 314 741 491 800 ...
output:
423 240 474 705 507 222 71 715 306 761 254 570 660 638 797 511 581 691 577 876 695 607 230 812 266 89 79 690 456 514 337 549 916 430 79 563 524 372 690 388 853 54 923 388 850 142 307 460 416 605 263 68 928 644 607 911 471 599 455 620 151 2 748 305 88 282 993 59 574 381 568 238 340 644 566 747 0 119 ...
result:
ok 995 numbers
Test #4:
score: 0
Accepted
time: 14ms
memory: 70916kb
input:
995 997 185 576 420 830 106 145 449 735 293 805 945 57 638 163 316 69 389 66 859 807 632 451 99 437 512 805 645 345 477 93 380 167 502 493 645 333 395 337 729 294 195 209 78 130 592 217 296 864 274 766 791 84 426 303 800 473 198 693 194 756 383 178 404 496 147 487 944 650 316 250 466 523 433 591 794...
output:
67 19 382 84 402 398 880 170 289 60 32 151 17 153 273 203 35 953 2 218 820 458 8 131 80 176 133 487 374 136 756 724 422 128 731 0 685 108 153 24 115 104 646 47 940 854 38 373 831 622 140 49 302 503 460 93 341 105 97 185 228 756 114 466 212 671 967 290 492 859 176 515 249 519 170 0 758 334 899 516 87...
result:
ok 997 numbers
Test #5:
score: 0
Accepted
time: 12ms
memory: 69652kb
input:
996 995 359 306 463 864 932 861 257 565 951 362 874 446 709 578 155 792 887 792 955 630 323 951 273 186 274 877 23 243 643 465 990 822 435 852 403 515 248 410 523 106 512 405 890 889 617 782 539 889 322 419 443 573 805 375 702 60 749 808 147 302 614 933 968 565 681 344 687 665 762 603 17 646 188 34 ...
output:
136 742 755 119 569 60 718 478 674 77 676 593 64 132 6 43 797 750 603 229 693 791 874 899 149 61 417 609 132 243 752 409 504 165 901 647 105 175 743 569 468 877 526 0 52 217 792 190 421 343 457 0 696 29 408 40 0 725 467 11 357 402 545 129 761 512 369 573 428 57 5 912 103 876 64 85 257 386 742 760 67...
result:
ok 995 numbers
Test #6:
score: 0
Accepted
time: 12ms
memory: 70956kb
input:
1000 1000 863 244 541 217 420 994 514 373 675 10 137 518 258 267 691 946 517 233 522 726 468 850 698 633 677 591 651 270 739 673 119 385 213 71 2 177 480 66 398 68 233 965 808 316 883 346 486 966 116 926 850 663 129 22 665 370 6 911 38 919 124 555 236 350 12 98 261 510 124 565 294 447 703 338 408 37...
output:
876 833 394 566 775 762 88 202 176 781 306 2 948 563 855 224 953 842 506 326 857 786 428 443 707 975 120 165 67 93 750 775 412 446 850 777 563 399 922 305 169 556 60 12 122 349 935 363 826 415 94 94 221 668 997 779 0 15 355 824 978 12 772 916 365 21 462 487 87 641 9 871 488 586 813 861 791 30 270 12...
result:
ok 1000 numbers
Test #7:
score: 0
Accepted
time: 12ms
memory: 70872kb
input:
998 995 968 598 292 481 163 318 24 536 222 338 486 556 600 574 730 474 653 981 669 378 513 79 766 774 100 543 895 535 752 93 883 427 338 874 253 536 235 384 761 822 790 235 823 909 598 348 319 746 650 219 710 485 862 816 847 978 397 497 108 894 61 939 860 633 545 743 130 362 782 855 72 965 906 146 5...
output:
885 513 845 589 139 453 34 725 407 679 629 662 345 547 303 609 463 207 585 227 290 350 105 382 270 19 380 707 413 366 491 284 784 887 642 672 547 651 126 16 26 771 752 723 315 244 66 626 169 923 720 449 889 812 406 53 745 218 151 583 551 520 286 668 626 316 892 937 339 804 7 149 470 32 723 753 341 2...
result:
ok 995 numbers
Test #8:
score: 0
Accepted
time: 7ms
memory: 69916kb
input:
1000 1000 118 698 770 781 232 191 699 983 873 604 753 289 556 223 577 705 614 711 50 822 59 41 169 346 535 785 956 299 570 831 933 382 193 64 943 608 973 38 283 425 679 272 769 954 369 484 202 454 916 768 474 703 502 751 453 156 202 791 864 285 834 371 631 580 131 132 724 408 789 344 735 982 835 826...
output:
35 241 333 424 60 661 739 244 78 185 303 353 72 756 112 94 0 756 518 941 931 1 217 908 332 211 432 64 930 747 716 474 313 510 827 362 773 257 632 490 417 710 273 179 453 466 473 718 230 714 491 703 74 108 484 40 220 214 0 170 843 121 182 538 606 662 824 0 666 425 620 75 182 16 389 422 0 343 365 299 ...
result:
ok 1000 numbers
Subtask #2:
score: 20
Accepted
Test #9:
score: 20
Accepted
time: 1952ms
memory: 220476kb
input:
999996 999996 921339 140126 955508 363759 958698 342406 280137 955674 907511 75721 189876 946586 152058 168837 541857 557702 84498 865987 185574 809224 704828 701026 815379 548000 989515 518951 335439 336866 745570 790616 766723 212893 926629 859003 51261 40866 592510 556235 324926 700261 320946 798...
output:
0 0 953730 0 0 512663 0 0 0 0 407467 0 0 0 0 420 0 0 0 0 0 0 513245 0 0 0 0 0 0 0 0 0 0 0 11756 0 0 7822 0 0 0 0 22726 0 0 0 8233 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 13818 349438 0 0 0 0 0 0 6803 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 8602 0 0 0 0 0 0 0 15717 0 0 0 0 0 0 0 0 0 0...
result:
ok 999996 numbers
Test #10:
score: 0
Accepted
time: 1910ms
memory: 218176kb
input:
999999 999998 593840 81071 226822 360556 984658 495723 774168 212723 961202 460976 425364 312068 135686 76747 312878 654073 77701 260718 263549 822714 513429 976716 926207 374094 338002 624578 897648 332005 630931 241967 134312 551284 743455 355739 997122 435568 642662 63663 795243 94444 696789 3776...
output:
491984 0 125735 422908 0 226183 0 0 0 2158 0 0 280064 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 19502 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 747 0 0 0 0 0 0 0 0 0 0 0 0 59265 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 ...
result:
ok 999998 numbers
Test #11:
score: 0
Accepted
time: 1973ms
memory: 222912kb
input:
1000000 1000000 883777 318082 13863 878428 601471 340063 593065 648191 228224 432858 585884 205059 770071 963599 897140 940808 68907 32537 396365 642545 822913 211348 629556 82339 190410 157689 907562 173596 271125 337580 145399 606492 749603 897091 193876 205903 678121 530830 947890 589055 721497 7...
output:
261157 0 0 52244 0 0 0 0 4610 0 20801 505827 0 0 0 655799 0 0 0 0 0 163473 0 0 113182 0 0 556199 0 0 0 282902 197726 0 0 0 521870 0 0 0 0 0 0 0 0 0 0 146288 0 136329 0 0 0 0 0 91372 0 0 0 0 0 522077 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 181410 0 0 0 0 0 0 ...
result:
ok 1000000 numbers
Test #12:
score: 0
Accepted
time: 1882ms
memory: 221212kb
input:
999999 999998 510701 119376 730813 348187 969509 347009 150616 323014 602592 62582 356110 705851 244692 610953 398605 700401 220533 880308 10280 261179 57162 967936 642021 39765 410482 274103 869979 489138 673553 368275 889697 840948 383673 63696 607963 107808 875626 9630 793170 959823 798227 760130...
output:
65013 21415 692431 0 388141 0 0 0 0 0 0 0 0 0 0 42859 0 0 0 0 0 0 0 0 0 0 8862 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 172112 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1215 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 6288 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 ...
result:
ok 999998 numbers
Test #13:
score: 0
Accepted
time: 1963ms
memory: 219888kb
input:
999995 999997 148480 214663 902145 539206 771718 173309 708903 967479 984809 352800 21198 668703 879442 719279 593199 82759 286519 788269 873747 641026 246815 368469 585243 532758 177189 437376 566499 996874 663718 794807 847945 784546 68802 611025 636042 793005 656312 200282 90301 316758 516692 913...
output:
408393 0 0 210017 0 0 0 0 0 0 0 0 0 0 0 0 0 0 34271 0 0 0 0 0 0 0 0 0 0 31774 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 624290 27190 0 0 0 0 0 0 0 0 2486 0 0 0 0 0 0 0 0 0 844 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 10393 0 0 0 0 0 0 0 0 0 0 0 0 49019 0 0 0 19256 0 0 0 0 0 0 62458 0 0 0 0 0 0 ...
result:
ok 999997 numbers
Test #14:
score: 0
Accepted
time: 1674ms
memory: 219444kb
input:
999997 999999 21022 22383 798350 250307 186761 593014 213847 210545 769838 227750 113146 776982 163493 384752 89954 142451 392976 865128 131868 401967 725617 848954 553332 555884 864058 712711 390463 443782 552326 132864 92265 612350 758766 28175 452611 460112 344799 865045 46279 695425 971996 40084...
output:
418555 110151 3026 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 33746 0 0 0 0 63321 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 60309 0 0 0 0 0 0 6997 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 3366 0 0 0 0 0 0 0 0 0 2...
result:
ok 999999 numbers
Test #15:
score: 0
Accepted
time: 1645ms
memory: 223284kb
input:
1000000 1000000 151138 713282 47031 196016 951306 826897 695178 570874 853734 782231 254275 640338 166145 420223 154398 814676 670384 826624 992734 757955 486563 187117 169107 198294 973559 847637 993679 950871 217983 940481 10443 754197 627178 253860 607235 514653 806520 269962 714084 706285 32303 ...
output:
493206 119482 243747 3831 0 30734 45299 0 84535 0 0 32866 0 0 0 0 0 0 663462 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 89699 0 76885 0 0 0 0 0 0 0 1347 0 0 0 114007 0 0 822812 0 0 0 0 0 0 0 0 0 0 0 0 0 0 8470 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 518 0 0 946947 0 0 0 0 ...
result:
ok 1000000 numbers
Test #16:
score: 0
Accepted
time: 1793ms
memory: 225116kb
input:
1000000 1000000 527391 935776 928283 415193 584695 629231 364709 289656 296798 845590 807666 903716 100319 286344 880595 598376 232292 301072 465491 18715 537421 144321 773917 271368 633706 520802 140917 281422 550382 123883 348051 422164 732339 760403 883443 660056 240883 539950 301009 698713 73859...
output:
956868 480655 0 0 3595 0 0 234921 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 4511 0 0 0 975 446781 0 0 0 1210 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 897203 8983 0 0 0 0 0 0 0 0 0 0 0 0 953761 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 ...
result:
ok 1000000 numbers
Subtask #3:
score: 0
Time Limit Exceeded
Test #17:
score: 0
Time Limit Exceeded
input:
999995 999997 261379 334440 985281 986034 549380 718157 670003 253925 533027 437989 326806 983213 965935 756259 229069 686789 331338 684961 957559 390618 937820 959719 338153 779814 582581 965418 634156 421264 308778 938878 913059 390904 481477 431492 739774 793015 901442 934600 256704 991485 366691...
output:
result:
Subtask #4:
score: 0
Time Limit Exceeded
Dependency #1:
100%
Accepted
Test #25:
score: 0
Time Limit Exceeded
input:
300000 300000 189563 143721 113019 232012 283009 152341 235960 146797 105782 100287 206719 212533 238247 192897 161513 101004 277069 129851 143907 67623 222005 158357 160618 31368 104158 90114 148304 15002 40521 169190 123876 140598 98925 113096 140488 204997 261142 106636 248565 219481 169567 27352...
output:
result:
Subtask #5:
score: 0
Skipped
Dependency #1:
100%
Accepted
Dependency #2:
100%
Accepted
Dependency #3:
0%