QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#389716 | #7436. Optimal Ordered Problem Solver | Kevin5307 | 0 | 3041ms | 449412kb | C++23 | 5.8kb | 2024-04-14 18:47:17 | 2024-04-14 18:47:18 |
Judging History
answer
//Author: Kevin
#include<bits/stdc++.h>
//#pragma GCC optimize("O2")
using namespace std;
#define ll long long
#define ull unsigned ll
#define pb emplace_back
#define mp make_pair
#define ALL(x) (x).begin(),(x).end()
#define rALL(x) (x).rbegin(),(x).rend()
#define srt(x) sort(ALL(x))
#define rev(x) reverse(ALL(x))
#define rsrt(x) sort(rALL(x))
#define sz(x) (int)(x.size())
#define inf 0x3f3f3f3f
#define pii pair<int,int>
#define lb(v,x) (int)(lower_bound(ALL(v),x)-v.begin())
#define ub(v,x) (int)(upper_bound(ALL(v),x)-v.begin())
#define uni(v) v.resize(unique(ALL(v))-v.begin())
#define longer __int128_t
void die(string S){puts(S.c_str());exit(0);}
int n,m;
int x[1001000],y[1001000];
int tp[1001000],u[1001000],v[1001000],qx[1001000],qy[1001000];
int tim[1001000];
vector<pii> vq[1001000],vp[1001000];
vector<int> vadd[1001000];
int ans[1001000];
namespace ds1
{
int bit[1001000];
void init(){memset(bit,0x3f,sizeof(bit));}
void update(int p,int v)
{
while(p)
{
bit[p]=min(bit[p],v);
p-=(p&(-p));
}
}
int query(int p)
{
int ans=inf;
while(p<1001000)
{
ans=min(ans,bit[p]);
p+=(p&(-p));
}
return ans;
}
}
namespace ds2
{
mt19937_64 rnd(20210448);
ull prior[1001000];
int x[1001000],y[1001000];
int tagx[1001000],tagy[1001000];
int ls[1001000],rs[1001000];
int siz[1001000];
int rt,tot;
void pushdown(int u)
{
if(tagx[u])
{
x[u]=tagx[u];
if(ls[u])
tagx[ls[u]]=tagx[u];
if(rs[u])
tagx[rs[u]]=tagx[u];
}
if(tagy[u])
{
y[u]=tagy[u];
if(ls[u])
tagy[ls[u]]=tagy[u];
if(rs[u])
tagy[rs[u]]=tagy[u];
}
tagx[u]=tagy[u]=0;
}
void pushup(int u){siz[u]=siz[ls[u]]+siz[rs[u]]+1;}
int merge(int u,int v)
{
if(!u||!v) return u^v;
if(prior[u]>prior[v])
{
pushdown(u);
rs[u]=merge(rs[u],v);
pushup(u);
return u;
}
else
{
pushdown(v);
ls[v]=merge(u,ls[v]);
pushup(v);
return v;
}
}
void splitx(int u,int tx,int &a,int &b)
{
if(!u)
{
a=b=0;
return ;
}
pushdown(u);
if(x[u]<=tx)
{
a=u;
splitx(rs[u],tx,rs[a],b);
pushup(a);
}
else
{
b=u;
splitx(ls[u],tx,a,ls[b]);
pushup(b);
}
}
void splitd(int u,int td,int &a,int &b)
{
if(!u)
{
a=b=0;
return ;
}
pushdown(u);
if(x[u]-y[u]<=td)
{
a=u;
splitd(rs[u],td,rs[a],b);
pushup(a);
}
else
{
b=u;
splitd(ls[u],td,a,ls[b]);
pushup(b);
}
}
void splity(int u,int ty,int &a,int &b)
{
if(!u)
{
a=b=0;
return ;
}
pushdown(u);
if(y[u]>=ty)
{
a=u;
splity(rs[u],ty,rs[a],b);
pushup(a);
}
else
{
b=u;
splity(ls[u],ty,a,ls[b]);
pushup(b);
}
}
void setx(int x,int y)
{
int a,b,c;
splity(rt,y+1,a,b);
splitx(b,x,b,c);
tagx[b]=x;
rt=merge(a,merge(b,c));
}
void sety(int x,int y)
{
int a,b,c;
splity(rt,y+1,a,b);
splitx(b,x,b,c);
tagy[b]=y;
rt=merge(a,merge(b,c));
}
int query(int x,int y)
{
int a,b,c;
splity(rt,y+1,a,b);
splitx(b,x,b,c);
int ans=siz[b];
rt=merge(a,merge(b,c));
return ans;
}
void insert(int xp,int yp)
{
tot++;
siz[tot]=1;
x[tot]=xp;
y[tot]=yp;
prior[tot]=rnd();
int a,b;
splitd(rt,xp-yp,a,b);
rt=merge(a,merge(tot,b));
}
int size(){return siz[rt];}
void check(int u=rt)
{
if(!u) return ;
pushdown(u);
check(ls[u]);
cerr<<"("<<x[u]<<","<<y[u]<<") ";
check(rs[u]);
}
}
class ds3
{
vector<int> vp[1001000];
vector<pii> vq[1001000];
int bit[1001000];
int coef;
void update(int p,int v)
{
while(p<1001000)
{
bit[p]+=v;
p+=(p&(-p));
}
}
int query(int p)
{
int ans=0;
while(p)
{
ans+=bit[p];
p-=(p&(-p));
}
return ans;
}
public:
ds3(int _coef=1):coef(_coef){}
void addp(int x,int y){vp[x].pb(y);}
void addq(int x,int y,int ind){vq[x].pb(y,ind);}
void calc()
{
for(int i=1;i<=n;i++)
{
for(auto y:vp[i])
update(y,1);
for(auto pr:vq[i])
ans[pr.second]+=coef*query(pr.first);
}
}
}ds3_1(-1),ds3_2(-1),ds3_3;
namespace ds4
{
int bit[1001000];
void update(int p,int v)
{
while(p)
{
bit[p]=max(bit[p],v);
p-=(p&(-p));
}
}
int query(int p)
{
int ans=0;
while(p<1001000)
{
ans=max(ans,bit[p]);
p+=(p&(-p));
}
return ans;
}
}
bool ban[1001000];
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
cin>>n>>m;
for(int i=1;i<=n;i++)
cin>>x[i]>>y[i];
for(int i=1;i<=m;i++)
{
cin>>tp[i]>>u[i]>>v[i]>>qx[i]>>qy[i];
tp[i]=3-tp[i];
}
for(int i=1;i<=m;i++)
vq[u[i]].pb(v[i],i);
for(int i=1;i<=n;i++)
vp[x[i]].pb(y[i],i);
ds1::init();
for(int i=n;i>=1;i--)
{
for(auto pr:vq[i])
ds1::update(pr.first,pr.second);
for(auto pr:vp[i])
tim[pr.second]=ds1::query(pr.first);
}
for(int i=1;i<=n;i++)
tim[i]=min(tim[i],m+1);
for(int i=1;i<=m;i++)
{
if(tp[i]==1)
ds4::update(u[i]-1,v[i]);
else
ds4::update(u[i],v[i]-1);
if(ds4::query(qx[i])>=qy[i])
ban[i]=1;
}
for(int i=1;i<=n;i++)
vadd[tim[i]].pb(i);
for(int i=1;i<=m;i++)
{
for(auto ind:vadd[i])
if(tp[i]==1)
ds2::insert(u[i],y[ind]);
else
ds2::insert(x[ind],v[i]);
if(tp[i]==1)
ds2::setx(u[i],v[i]);
else
ds2::sety(u[i],v[i]);
ans[i]=ds2::query(qx[i],qy[i]);
ans[i]-=ds2::size();
}
for(int i=1;i<=n;i++)
{
ds3_1.addp(n+1-x[i],m+2-tim[i]);
ds3_2.addp(n+1-y[i],m+2-tim[i]);
ds3_3.addp(n+1-x[i],n+1-y[i]);
}
for(int i=1;i<=m;i++)
{
ds3_1.addq(n-qx[i],m+1-i,i);
ds3_2.addq(n-qy[i],m+1-i,i);
ds3_3.addq(n-qx[i],n-qy[i],i);
}
ds3_1.calc();
ds3_2.calc();
ds3_3.calc();
for(int i=1;i<=m;i++)
if(!ban[i])
cout<<ans[i]+n<<'\n';
else
cout<<"0\n";
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Subtask #1:
score: 0
Wrong Answer
Test #1:
score: 0
Wrong Answer
time: 19ms
memory: 192328kb
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 121st numbers differ - expected: '105', found: '106'
Subtask #2:
score: 0
Wrong Answer
Test #9:
score: 0
Wrong Answer
time: 3041ms
memory: 449412kb
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 488641 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:
wrong answer 66th numbers differ - expected: '349438', found: '488641'
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
Skipped
Dependency #1:
0%
Subtask #5:
score: 0
Skipped
Dependency #1:
0%