QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#75750 | #5310. Painting | A_zjzj | WA | 847ms | 38192kb | C++14 | 2.3kb | 2023-02-06 09:48:14 | 2023-02-06 09:48:18 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
using ll=long long;
const int N=3e5+10,K=__lg(N)+2;
int n,W,a[N],b[N],fa[K][N],dep[N];
struct cmp{
bool operator () (const int &x,const int &y)const{
return a[x]<a[y];
}
};
set<int,cmp>s;
struct frac{
ll x,y;
frac trs()const{
ll g=__gcd(abs(x),abs(y));
return {x/g,y/g};
}
bool operator < (const frac &a)const{
return x*a.y<y*a.x;
}
bool operator <= (const frac &a)const{
return x*a.y<=y*a.x;
}
frac operator * (const int &a)const{
return {x*a,y};
}
frac operator + (const frac &a)const{
return {x*a.y+a.x*y,y*a.y};
}
}r[N];
void write(frac x){
x=x.trs(),printf("%lld/%lld",x.x,x.y);
}
frac calc(int i,int j){
ll x=a[i]-a[j],y=b[j]-a[j]-b[i]+a[i];
if(y<0)x=-x,y=-y;
return {x,y};
}
int LCA(int u,int v){
if(dep[u]<dep[v])swap(u,v);
for(int i=K-1;~i;i--)if(dep[fa[i][u]]>=dep[v])u=fa[i][u];
if(u==v)return u;
for(int i=K-1;~i;i--)if(fa[i][u]^fa[i][v])u=fa[i][u],v=fa[i][v];
return fa[0][u];
}
bool find(int p,int u,int t,bool tag=0){
for(int i=K-1;~i;i--){
int v=fa[i][u];
if(v==t&&!tag)continue;
frac tmp=calc(v,p);
if(tmp.x<0||r[v]<tmp)
u=v;
}
frac tmp=calc(u,p);
if(r[u]<tmp||tmp.x<0)u=fa[0][u];
tmp=calc(u,p);
if(r[u]<tmp||tmp.x<0)return 0;
if(r[p]<tmp)return 0;
fa[0][p]=u;
dep[p]=dep[u]+1;
r[p]=tmp;
for(int i=1;i<K;i++)fa[i][p]=fa[i-1][fa[i-1][p]];
return 1;
}
int main(){
scanf("%d%d",&n,&W);
a[0]=b[0]=0,s.insert(0);
a[n+1]=b[n+1]=1e6+1,s.insert(n+1);
r[0]=r[n+1]={1,1};
dep[0]=dep[n+1]=1;
for(int i=0;i<K;i++)fa[i][0]=0,fa[i][n+1]=n+1;
for(int i=1,op;i<=n;i++){
r[i]={1,1};
scanf("%d%d%d",&a[i],&b[i],&op);
auto it=s.lower_bound(i);
int v=*it,u=*prev(it);
if(fa[K-1][u]!=fa[K-1][v]){
bool x=find(i,u,fa[K-1][u],1),y=find(i,v,fa[K-1][v],1);
if(!x&&!y){
dep[i]=1;
for(int j=0;j<K;j++)fa[j][i]=i;
r[i]=(frac){1,1};
}
}
else{
int t=LCA(u,v);
bool x=find(i,u,t),y=find(i,v,t);
if(!x&&!y){
dep[i]=dep[t]+1;
fa[0][i]=t;
for(int j=1;j<K;j++)fa[j][i]=fa[j-1][fa[j-1][i]];
r[i]=calc(i,t);
}
}
if(op)s.insert(i);
putchar('(');
write(r[i]*W);
putchar(',');
write(r[i]*b[i]+(frac){r[i].y-r[i].x,r[i].y}*a[i]);
puts(")");
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 3ms
memory: 5712kb
input:
4 3 1 2 1 2 1 1 3 1 0 3 2 1
output:
(3/1,2/1) (3/2,3/2) (2/1,5/3) (3/1,2/1)
result:
ok 4 lines
Test #2:
score: 0
Accepted
time: 331ms
memory: 35332kb
input:
300000 894665 1 1000000 1 2 999999 1 3 999997 1 4 999994 1 5 999990 1 6 999985 1 7 999979 1 8 999972 1 9 999964 1 10 999955 1 11 999945 1 12 999934 1 13 999922 1 14 999909 1 15 999895 1 16 999880 1 17 999864 1 18 999847 1 19 999829 1 20 999810 1 21 999790 1 22 999769 1 23 999747 1 24 999724 1 25 999...
output:
(894665/1,1000000/1) (894665/2,1000001/2) (894665/3,1000003/3) (894665/4,500003/2) (178933/1,200002/1) (894665/6,1000015/6) (894665/7,1000021/7) (894665/8,250007/2) (894665/9,1000036/9) (178933/2,200009/2) (894665/11,1000055/11) (894665/12,500033/6) (894665/13,1000078/13) (894665/14,1000091/14) (178...
result:
ok 300000 lines
Test #3:
score: 0
Accepted
time: 324ms
memory: 35296kb
input:
300000 748539 1 1000000 1 2 999999 1 3 999997 1 4 999994 1 5 999990 1 6 999985 1 7 999979 1 8 999972 1 9 999964 1 10 999955 1 11 999945 1 12 999934 1 13 999922 1 14 999909 1 15 999895 1 16 999880 1 17 999864 1 18 999847 1 19 999829 1 20 999810 1 21 999790 1 22 999769 1 23 999747 1 24 999724 1 25 999...
output:
(748539/1,1000000/1) (748539/2,1000001/2) (249513/1,1000003/3) (748539/4,500003/2) (748539/5,200002/1) (249513/2,1000015/6) (748539/7,1000021/7) (748539/8,250007/2) (83171/1,1000036/9) (748539/10,200009/2) (68049/1,1000055/11) (249513/4,500033/6) (748539/13,1000078/13) (748539/14,1000091/14) (249513...
result:
ok 300000 lines
Test #4:
score: -100
Wrong Answer
time: 847ms
memory: 38192kb
input:
300000 329779 725400 466189 0 162004 217124 0 17706 369295 0 143330 449439 0 974743 495692 0 476940 609424 0 307270 769869 0 664031 252064 0 350818 610178 1 432310 398376 1 578066 277363 0 891345 770652 0 815291 550496 0 756083 89624 0 867560 132663 0 668047 648059 0 758279 558971 0 647877 798646 0 ...
output:
(329779/1,466189/1) (329779/1,217124/1) (329779/1,369295/1) (329779/1,449439/1) (329779/1,495692/1) (329779/1,609424/1) (329779/1,769869/1) (329779/1,252064/1) (329779/1,610178/1) (13437175134/146647,62014289806/146647) (10705945456/80009,36488460402/80009) (329779/1,770652/1) (153173441467/524155,6...
result:
wrong answer 44th lines differ - expected: '(26682418890/674329,401483447931/674329)', found: '(92437383479/557202,134087679298/278601)'