QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#434771 | #8793. Toilets | ucup-team3510# | WA | 2ms | 12148kb | C++14 | 4.6kb | 2024-06-08 17:18:13 | 2024-06-08 17:18:27 |
Judging History
answer
#include <bits/stdc++.h>
#define ll long long
#define N 200011
using namespace std;
int n,m;ll L;
set<ll> Tpos;
struct Ppers{ll x,t;int id;Ppers(int _x=0){x=t=id=-1;}Ppers(ll _x,ll _t,int _id){x=_x;t=_t;id=_id;}};
bool operator<(Ppers a,Ppers b)
{
if(a.x==b.x)return a.t>b.t;
else return a.x<b.x;
}
struct Npers{ll x,t;int id;Npers(int _x=0){x=t=id=-1;}Npers(ll _x,ll _t,int _id){x=_x;t=_t;id=_id;}};
bool operator<(Npers a,Npers b)
{
if(a.x==b.x)return a.t<b.t;
else return a.x<b.x;
}
set<Npers> Npos;set<Ppers> Ppos;
struct event
{
ll t,t_;int typ;
Npers n;Ppers p;
ll x;
event(){t=t_=typ=x=-1;}
};
// typ=0: Npers n gets a toilet at x
// typ=1: Ppers p gets a toilet at x
// typ=2: A toilet appears at x
// typ=3: A Npers n appears at x
// typ=4: A Ppers p appears at x
bool operator<(event a,event b)
{
if(a.t!=b.t)return a.t<b.t;
if(a.typ>=2||b.typ>=2)
{
if(a.typ!=b.typ)return a.typ>b.typ;
else return a.x<b.x;
}
else return a.t_<b.t_;
}
set<event> Est;
template<typename T>
T prv(set<T> &Tpos,T x)
{
if(Tpos.empty())return -1;
auto it=Tpos.upper_bound(x);
if(it==Tpos.begin())return *--Tpos.end();
else return *--it;
}
template<typename T>
T nxt(set<T> &Tpos,T x)
{
if(Tpos.empty())return -1;
auto it=Tpos.lower_bound(x);
if(it==Tpos.end())return *Tpos.begin();
else return *it;
}
ll Tx[N];
ll t[N],p[N],d[N];
char s[11];
ll dis(ll u,ll v){u=(u%L+L)%L;v=(v%L+L)%L;return (v-u+L)%L;}
ll resT[N],resX[N];
int main()
{
scanf("%d%d%lld",&n,&m,&L);
for(int i=1;i<=m;++i)
{
event e;
e.t=0;
e.typ=2;
scanf("%lld",&e.x);
Est.insert(e);
}
for(int i=1;i<=n;++i)
{
scanf("%lld%lld%s%lld",t+i,p+i,s+1,d+i);
event e;
if(s[1]=='+')
{
e.t=t[i];
e.typ=4;
e.x=p[i];
e.p=Ppers(p[i],t[i],i);
}
else
{
e.t=t[i];
e.typ=3;
e.x=p[i];
e.n=Npers(p[i],t[i],i);
}
Est.insert(e);
}
while(!Est.empty())
{
event e=*Est.begin();
Est.erase(Est.begin());
// printf("========================found event e typ:%d\n",e.typ);
// printf("t:%lld t_:%lld typ:%d x:%lld\n",e.t,e.t_,e.typ,e.x);
// printf("e.n:(%lld,%lld,%d) e.p(%lld,%lld,%d)\n",e.n.x,e.n.t,e.n.id,e.p.x,e.p.t,e.p.id);
if(e.typ==0)
{
if(Npos.find(e.n)==Npos.end())continue;
if(Tpos.find(e.x)==Tpos.end())
{
ll x=prv(Tpos,e.x);
// printf("aiming for toilet x:%lld\n",x);
if(~x)
{
event ne;
ne.t=e.t+dis(x,e.x);
ne.n=e.n;ne.x=x;
ne.t_=e.n.t;
ne.typ=0;
Est.insert(ne);
}
}
else
{//printf("success\n");
Npos.erase(e.n);
Tpos.erase(e.x);
resT[e.n.id]=e.t;resX[e.n.id]=e.x;
event ne;
ne.t=e.t+d[e.n.id];
ne.typ=2;
ne.x=e.x;
Est.insert(ne);
}
}
else if(e.typ==1)
{
if(Ppos.find(e.p)==Ppos.end())continue;
if(Tpos.find(e.x)==Tpos.end())
{
ll x=nxt(Tpos,e.x);
// printf("aiming for toilet x:%lld\n",x);
if(~x)
{
event ne;
ne.t=e.t+dis(e.x,x);
ne.p=e.p;ne.x=x;
ne.t_=e.p.t;
ne.typ=1;
Est.insert(ne);
}
}
else
{//printf("success\n");
Ppos.erase(e.p);
Tpos.erase(e.x);
resT[e.p.id]=e.t;resX[e.p.id]=e.x;
event ne;
ne.t=e.t+d[e.p.id];
ne.typ=2;
ne.x=e.x;
Est.insert(ne);
}
}
else if(e.typ==2)
{
Npers n=nxt(Npos,Npers((e.x+e.t)%L,-1e18,0));
// printf("Npers %d aims for toilet %lld\n",n.id,e.x);
if(~n.id)
{
event ne;
ne.t=e.t+dis(e.x,n.x-e.t);
ne.n=n;ne.x=e.x;
ne.t_=n.t;
ne.typ=0;
Est.insert(ne);
}
Ppers p=prv(Ppos,Ppers(((e.x-e.t)%L+L)%L,-1e18,0));
// printf("Ppers %d aims for toilet %lld\n",p.id,e.x);
if(~p.id)
{
event ne;
ne.t=e.t+dis(p.x+e.t,e.x);
ne.p=p;ne.x=e.x;
ne.t_=p.t;
ne.typ=1;
Est.insert(ne);
}
Tpos.insert(e.x);
}
else if(e.typ==3)
{
ll x=prv(Tpos,e.x);
// printf("aiming for toilet x:%lld\n",x);
Npers tn((e.n.x+e.n.t)%L,e.n.t,e.n.id);
if(~x)
{
event ne;
ne.t=e.t+dis(x,e.n.x);
ne.n=tn;ne.x=x;
ne.t_=e.n.t;
ne.typ=0;
Est.insert(ne);
}
Npos.insert(Npers((e.n.x+e.n.t)%L,e.n.t,e.n.id));
}
else if(e.typ==4)
{
ll x=nxt(Tpos,e.x);
// printf("aiming for toilet x:%lld\n",x);
Ppers tp(((e.p.x-e.p.t)%L+L)%L,e.p.t,e.p.id);
if(~x)
{
event ne;
ne.t=e.t+dis(e.p.x,x);
ne.p=tp;ne.x=x;
ne.t_=e.p.t;
ne.typ=1;
Est.insert(ne);
}
Ppos.insert(Ppers(((e.p.x-e.p.t)%L+L)%L,e.p.t,e.p.id));
}
}
for(int i=1;i<=n;++i)printf("%lld %lld\n",resX[i],resT[i]);
fclose(stdin);fclose(stdout);return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 10044kb
input:
5 3 45 10 20 30 0 0 + 200 2 5 + 10 20 40 - 100 21 16 + 10 50 0 + 22
output:
20 20 10 7 30 30 10 60 10 105
result:
ok 10 numbers
Test #2:
score: 0
Accepted
time: 2ms
memory: 9988kb
input:
1 1 1 0 0 0 - 1
output:
0 0
result:
ok 2 number(s): "0 0"
Test #3:
score: 0
Accepted
time: 2ms
memory: 12148kb
input:
5 3 33 3 24 23 12 24 - 9 16 28 - 1 17 27 - 9 19 26 - 5 32 22 - 2
output:
24 12 23 21 3 41 24 21 3 51
result:
ok 10 numbers
Test #4:
score: 0
Accepted
time: 0ms
memory: 10032kb
input:
4 5 6 1 3 4 2 0 2 1 + 2 7 3 + 6 9 0 + 9 10 1 - 6
output:
1 2 3 7 0 9 1 10
result:
ok 8 numbers
Test #5:
score: -100
Wrong Answer
time: 0ms
memory: 10092kb
input:
736 30 100500 99382 85511 67593 53450 55531 9959 37170 57546 52666 62342 50707 71285 65933 19874 2092 100255 23965 83091 45652 64171 100128 19518 21445 96069 79781 52642 37943 95321 97569 69154 0 44619 + 7052 2 72499 + 29247 3 53785 - 35614 5 81887 + 64475 7 8561 + 31641 8 95471 - 22654 9 61040 - 44...
output:
53450 310331 95321 22824 53450 338 67593 186711 23965 718911 95321 158 83091 580958 62342 71243 50707 602820 83091 183 2092 375130 96069 552638 100128 541370 64171 5285 50707 288492 45652 896373 2092 284 85511 720931 55531 713428 53450 483192 69154 5302 83091 155808 57546 351069 2092 231938 85511 60...
result:
wrong answer 32nd numbers differ - expected: '795873', found: '896373'