QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#382965 | #7436. Optimal Ordered Problem Solver | marher | 0 | 1578ms | 249596kb | C++17 | 5.4kb | 2024-04-08 20:34:14 | 2024-04-08 20:34:15 |
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 l,r,w,la;int opt,siz,rd;
void mk(poi d,int o)
{
if(o&1)opt|=1,l.y=r.y=w.y=la.y=d.y;
if(o&2)opt|=2,l.x=r.x=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,mi[N];
int *g[N];
#define ls ch[x][0]
#define rs ch[x][1]
void up(int x)
{
t[x].l=ls?t[ls].l:t[x].w;
t[x].r=rs?t[rs].r:t[x].w;
t[x].siz=t[ls].siz+t[rs].siz+1;
}
int make_new(poi w)
{
int x=++tot;
t[x]=(node){w,w,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;
if(t[x].l.in(d)&&t[x].r.in(d))return t[x].mk(d,opt);
if(t[x].r.y>d.y||t[x].l.x>d.x)return;
down(x);dfs(ls,d,opt);dfs(rs,d,opt);
if(t[x].w.in(d))
{
if(opt==1)t[x].w.y=d.y;
else t[x].w.x=d.x;
}
up(x);
}
int find(int x,poi d)
{
if(!x||t[x].r.y>d.y||t[x].l.x>d.x)return 0;
if(t[x].l.in(d)&&t[x].r.in(d))return t[x].siz;
down(x);return find(ls,d)+find(rs,d)+t[x].w.in(d);
}
void insert(int d,int x)
{
for(int i=d;i<=n;i+=(i&(-i)))mi[i]=min(mi[i],x);
}
int Find(int d)
{
int ans=1e9;
for(int i=d;i;i-=(i&(-i)))ans=min(ans,mi[i]);
return ans;
}
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;
int tim;
vector<int>ad[N];
struct pask
{
int opt,x,y,id;
friend bool operator<(pask a,pask b)
{
return a.x==b.x?a.opt<b.opt:a.x>b.x;
}
}rq[N];
vector<pair<int,int>>ask[N];
struct que
{
int opt,x,y,X,Y;
void in()
{
read(opt,x,y,X,Y);
}
}ak[N];
int main()
{
srand(19260817);
// freopen("in","r",stdin);
// freopen("out","w",stdout);
read(n,m);now=n;
for(int i=1;i<=n;i++)read(a[i].x,a[i].y),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++)rq[i]=(pask){1,a[i].x,a[i].y,i};
for(int i=1;i<=m;i++)ak[i].in(),rq[i+n]=(pask){0,ak[i].x,ak[i].y,i};
for(int i=1;i<=n;i++)mi[i]=1e9+7;sort(rq+1,rq+1+n+m);
for(int i=1;i<=n+m;i++)
{
if(rq[i].opt==0)insert(n-rq[i].y+1,rq[i].id);
else
{
int w=Find(n-rq[i].y+1);
if(w<=m)ad[w].push_back(rq[i].id);
}
}
for(int i=1;i<=m;i++)
{
auto [opt,x,y,X,Y] = ak[i];
rinsert(x,y);dfs(ro,(poi){x,y},opt);
for(auto d:ad[i])
{
xx.insert(a[d].x,-1),yy.insert(a[d].y,-1);
if(opt==1)a[d].y=y;else a[d].x=x;
int x=0,y=0;now--;
split(ro,a[d],x,y);
ro=merge(merge(x,make_new(a[d])),y);
}
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));
}
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: 0
Wrong Answer
Test #1:
score: 0
Wrong Answer
time: 15ms
memory: 116660kb
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:
328 390 746 126 686 48 151 784 816 126 247 -18 461 -404 -126 304 871 782 734 -168 627 371 -327 754 -244 -873 16 974 480 412 350 689 459 558 105 -291 -7 -773 -59 131 120 446 135 828 311 578 981 684 -276 -516 -360 494 228 138 252 9 303 -260 -41 334 -695 521 -786 254 409 90 -551 0 -84 598 669 546 415 6...
result:
wrong answer 1st numbers differ - expected: '423', found: '328'
Subtask #2:
score: 0
Wrong Answer
Test #9:
score: 0
Wrong Answer
time: 1578ms
memory: 249596kb
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 953251 0 0 504345 0 0 0 0 361252 0 0 0 0 -35338 0 0 0 0 0 0 506422 0 0 0 0 0 0 0 0 0 0 0 -1848 0 0 -12220 0 0 0 0 21965 0 0 0 6191 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 4460 317305 0 0 0 0 0 0 -14089 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 -9838 0 0 0 0 0 0 0 8408 0 0 0 0 0 0 0...
result:
wrong answer 3rd numbers differ - expected: '953730', found: '953251'
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%