QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#381693 | #7436. Optimal Ordered Problem Solver | 2745518585 | 0 | 2708ms | 202772kb | C++20 | 6.8kb | 2024-04-07 20:26:49 | 2024-04-07 20:26:50 |
Judging History
answer
#include<cstdio>
#include<algorithm>
#include<vector>
using namespace std;
const int N=10000001;
int n,m,rt,f[N];
bool h[N];
struct
{
int x,y,t;
}a1[N];
struct
{
int z,x,y;
}a2[N];
struct
{
int x,y;
}a3[N];
vector<pair<int,int>> b1[N],b2[N];
namespace fhq
{
int tot;
struct tree
{
int x1,x2,k1,k2,l,r,s,h;
}T[N];
void pushup(int x)
{
T[x].s=T[T[x].l].s+T[T[x].r].s+1;
}
void pushdown(int x)
{
if(T[x].k1)
{
if(T[x].l) T[T[x].l].x1=T[T[x].l].k1=T[x].k1;
if(T[x].r) T[T[x].r].x1=T[T[x].r].k1=T[x].k1;
T[x].k1=0;
}
if(T[x].k2)
{
if(T[x].l) T[T[x].l].x2=T[T[x].l].k2=T[x].k2;
if(T[x].r) T[T[x].r].x2=T[T[x].r].k2=T[x].k2;
T[x].k2=0;
}
}
void split(int x,int k,int &x1,int &x2)
{
if(x==0)
{
x1=x2=0;
return;
}
pushdown(x);
if(T[x].x1-T[x].x2<=k)
{
x1=x;
split(T[x].r,k,T[x].r,x2);
}
else
{
x2=x;
split(T[x].l,k,x1,T[x].l);
}
pushup(x);
}
int merge(int x1,int x2)
{
if(x1==0||x2==0) return x1|x2;
pushdown(x1);
pushdown(x2);
if(T[x1].h<T[x2].h)
{
T[x1].r=merge(T[x1].r,x2);
pushup(x1);
return x1;
}
else
{
T[x2].l=merge(x1,T[x2].l);
pushup(x2);
return x2;
}
}
void add(int k1,int k2)
{
int x1,x2;
split(rt,k1-k2,x1,x2);
T[++tot].x1=k1;
T[tot].x2=k2;
T[tot].l=T[tot].r=0;
T[tot].s=1;
T[tot].h=rand();
rt=merge(merge(x1,tot),x2);
}
int num1(int x,int k)
{
if(x==0) return 1e9;
pushdown(x);
if(k<T[x].x2) return num1(T[x].r,k);
int p=num1(T[x].l,k);
if(p==1e9) return T[x].x1-T[x].x2;
return p;
}
int num2(int x,int k)
{
if(x==0) return 1e9;
pushdown(x);
if(k<T[x].x1) return num2(T[x].l,k);
int p=num2(T[x].r,k);
if(p==1e9) return T[x].x1-T[x].x2;
return p;
}
}
namespace sgt1
{
int T[N];
void add(int x,int k)
{
while(x<=n) T[x]=min(T[x],k),x+=x&-x;
}
int sum(int x)
{
int s=1e9;
while(x>=1) s=min(s,T[x]),x-=x&-x;
return s;
}
}
namespace sgt2
{
int T[N];
void add(int x,int k)
{
while(x<=n) T[x]+=k,x+=x&-x;
}
int sum(int x)
{
int s=0;
while(x>=1) s+=T[x],x-=x&-x;
return s;
}
}
int main()
{
scanf("%d%d",&n,&m);
for(int i=1;i<=n;++i)
{
scanf("%d%d",&a1[i].x,&a1[i].y);
}
for(int i=1;i<=m;++i)
{
scanf("%d%d%d%d%d",&a2[i].z,&a2[i].x,&a2[i].y,&a3[i].x,&a3[i].y);
}
for(int i=1;i<=m;++i)
{
b1[a2[i].x].push_back(make_pair(a2[i].y,i));
}
for(int i=1;i<=n;++i)
{
b2[a1[i].x].push_back(make_pair(a1[i].y,i));
}
for(int i=1;i<=n;++i) sgt1::T[i]=m+1;
for(int i=n;i>=1;--i)
{
for(auto j:b1[i]) sgt1::add(n-j.first+1,j.second);
for(auto j:b2[i]) a1[j.second].t=sgt1::sum(n-j.first+1);
}
for(int i=1;i<=n;++i) --f[a1[i].t-1];
for(int i=m;i>=1;--i) f[i]+=f[i+1];
// for(int i=1;i<=n;++i) printf("%d ",a1[i].t);printf("\n");
for(int i=1;i<=n;++i) b1[i].clear(),b2[i].clear();
for(int i=1;i<=n;++i)
{
b1[a1[i].x].push_back(make_pair(a1[i].y,a1[i].t));
}
for(int i=1;i<=m;++i)
{
b2[a3[i].x].push_back(make_pair(a3[i].y,i));
}
for(int i=1;i<=n;++i) sgt1::T[i]=m+1;
for(int i=1;i<=n;++i)
{
for(auto j:b1[i]) sgt1::add(j.first,m-j.second+1);
for(auto j:b2[i]) h[j.second]=m-sgt1::sum(j.first)+1>j.second;
}
for(int i=1;i<=m+1;++i) b1[i].clear(),b2[i].clear();
for(int i=1;i<=n;++i)
{
b1[a1[i].t].push_back(make_pair(a1[i].x,1));
}
for(int i=1;i<=m;++i)
{
b2[i].push_back(make_pair(a3[i].x,i));
}
for(int i=1;i<=n;++i) sgt2::T[i]=0;
for(int i=m;i>=1;--i)
{
for(auto j:b1[i+1]) sgt2::add(j.first,j.second);
for(auto j:b2[i]) f[j.second]+=sgt2::sum(j.first);
}
for(int i=1;i<=m+1;++i) b1[i].clear(),b2[i].clear();
for(int i=1;i<=n;++i)
{
b1[a1[i].t].push_back(make_pair(a1[i].y,1));
}
for(int i=1;i<=m;++i)
{
b2[i].push_back(make_pair(a3[i].y,i));
}
for(int i=1;i<=n;++i) sgt2::T[i]=0;
for(int i=m;i>=1;--i)
{
for(auto j:b1[i+1]) sgt2::add(j.first,j.second);
for(auto j:b2[i]) f[j.second]+=sgt2::sum(j.first);
}
for(int i=1;i<=n;++i) b1[i].clear(),b2[i].clear();
for(int i=1;i<=n;++i)
{
b1[a1[i].x].push_back(make_pair(a1[i].y,1));
}
for(int i=1;i<=m;++i)
{
b2[a3[i].x].push_back(make_pair(a3[i].y,i));
}
for(int i=1;i<=n;++i) sgt2::T[i]=0;
for(int i=n;i>=1;--i)
{
for(auto j:b2[i]) f[j.second]+=sgt2::sum(n-j.first);
for(auto j:b1[i]) sgt2::add(n-j.first+1,j.second);
}
for(int i=1;i<=m;++i) b1[i].clear();
for(int i=1;i<=n;++i)
{
b1[a1[i].t].push_back(make_pair(a1[i].x,a1[i].y));
}
for(int i=1;i<=m;++i)
{
int l=fhq::num1(rt,a2[i].y),r=fhq::num2(rt,a2[i].x);
// printf("%d %d\n",l,r);
if(l!=1e9&&r!=1e9)
{
int x1,x2,x3;
fhq::split(rt,l-1,x1,x2);
fhq::split(x2,r,x2,x3);
if(a2[i].z==1)
{
fhq::T[x2].x2=a2[i].y;
fhq::T[x2].k2=a2[i].y;
}
else
{
fhq::T[x2].x1=a2[i].x;
fhq::T[x2].k1=a2[i].x;
}
rt=fhq::merge(fhq::merge(x1,x2),x3);
}
for(auto j:b1[i])
{
if(a2[i].z==1) j.second=max(j.second,a2[i].y);
else j.first=max(j.first,a2[i].x);
fhq::add(j.first,j.second);
}
l=fhq::num1(rt,a3[i].y),r=fhq::num2(rt,a3[i].x);
// printf("%d %d\n",l,r);
// printf("%d\n",f[i]);
if(l==1e9||r==1e9)
{
if(h[i]==false) f[i]=0;
}
else
{
int x1,x2,x3;
fhq::split(rt,l-1,x1,x2);
fhq::split(x2,r,x2,x3);
// printf("%d %d %d\n",fhq::T[x1].s,fhq::T[x2].s,fhq::T[x3].s);
f[i]+=fhq::T[x2].s;
rt=fhq::merge(fhq::merge(x1,x2),x3);
}
printf("%d\n",f[i]);
}
return 0;
}
详细
Subtask #1:
score: 0
Wrong Answer
Test #1:
score: 0
Wrong Answer
time: 19ms
memory: 18280kb
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:
wrong answer 216th numbers differ - expected: '0', found: '23'
Subtask #2:
score: 0
Wrong Answer
Test #9:
score: 0
Wrong Answer
time: 2708ms
memory: 202772kb
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 43735 953730 74519 227518 512663 45703 330744 341462 70474 407467 0 0 0 0 420 0 0 0 0 6576 0 513245 0 0 0 0 0 0 0 0 0 0 989 11756 8190 0 7822 0 0 0 6683 22726 0 0 0 8233 0 0 0 0 0 0 0 0 0 0 0 0 65172 19842 0 15672 0 13818 349438 0 0 0 0 0 0 6803 0 0 55787 0 0 0 280378 391933 2959 67818 324848 2493...
result:
wrong answer 2nd numbers differ - expected: '0', found: '43735'
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:
160635 633543 123519 313576 450015 383636 574186 2373 203701 326075 117994 567275 652824 199778 380317 380374 105875 373857 788346 703176 609801 648161 367059 497975 57979 478851 745054 75935 543062 251837 769828 436489 480966 235835 509625 757188 763486 396842 262680 2240 267171 165787 558963 16523...
result:
Subtask #4:
score: 0
Skipped
Dependency #1:
0%
Subtask #5:
score: 0
Skipped
Dependency #1:
0%