QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#22758 | #2365. Flight Collision | DaBenZhongXiaSongKuaiDi# | WA | 3ms | 3824kb | C++20 | 2.3kb | 2022-03-10 16:06:31 | 2022-04-30 01:38:03 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn=(int)1e5+5, p=998244353;
struct Node {int x,y,T;double t;bool operator < (const Node&q)const{return t==q.t ? x==q.x ? y<q.y : x<q.x : t<q.t;}};
int n,x[maxn],v[maxn],vis[maxn];
set<int>res; set<Node>sta; vector<int>pre,nxt;
inline int FP(int b,int k=p-2){
int ret=1,mul=b;
while(k) {if(k&1)ret=ret*mul%p; mul=mul*mul%p; k>>=1;} return ret;
}
inline double calc(int a,int b){if(x[a]>x[b])swap(a,b);return v[a]>v[b] ? (double)(x[b]-x[a])/(double)(v[a]-v[b]) : -1;}
inline int calc_int(int a,int b){if(x[a]>x[b])swap(a,b);return (ll)(x[b]-x[a])*FP(v[a]-v[b])%p;}
inline bool chk(Node N){return !vis[N.x] && !vis[N.y];}
int main(){
scanf("%d",&n);
for(int al=1;al<=n;al++) scanf("%d%d",&x[al],&v[al]),res.insert(al);
for(int al=1;al<n;al++){
double t=calc(al,al+1);
if(t>0)
sta.insert((Node){al,al+1,calc_int(al,al+1),t});
}
while(!sta.empty()){
while(!sta.empty() && !chk(*sta.begin())) sta.erase(sta.begin());
if(sta.empty()) break;
Node h=(*sta.begin()); sta.erase(sta.begin());
int A=h.x,B=h.y; res.erase(A), res.erase(B);
vis[A]=vis[B]=1;
// printf("down %d %d\n",A,B);
pre.clear(); pre.push_back(A), pre.push_back(B);
while(!sta.empty()){
while(!sta.empty() && !chk(*sta.begin()))
// printf("eli %d %d\n",(*sta.begin()).x,(*sta.begin()).y),
sta.erase(sta.begin());
if(sta.empty() || (*sta.begin()).T!=h.T) break;
Node H=(*sta.begin()); sta.erase(sta.begin());
res.erase(H.x), res.erase(H.y);
// printf("down %d %d\n",H.x,H.y);
vis[H.x]=vis[H.y]=1;
pre.push_back(H.x), pre.push_back(H.y);
}
nxt.clear();
for(auto X:pre){
auto itl=res.lower_bound(X), itr=res.upper_bound(X);
if(itl != res.begin()) --itl, nxt.push_back(*itl);
if(itr != res.end()) ++itr, nxt.push_back(*itr);
}
sort(nxt.begin(),nxt.end());
unique(nxt.begin(),nxt.end());
for(int al=0,l=nxt.size()-1;al<l;al++){
double t=calc(nxt[al],nxt[al+1]);
if(t>0)
sta.insert((Node){nxt[al],nxt[al+1],calc_int(nxt[al],nxt[al+1]),t});
// printf("in %d %d %d %.2lf\n",nxt[al],nxt[al+1],calc_int(nxt[al],nxt[al+1]),calc(nxt[al],nxt[al+1]));
}
}
printf("%d\n",res.size());
for(auto X:res) printf("%d ",X);
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 2ms
memory: 3824kb
input:
1 -4 13
output:
1 1
result:
ok 2 lines
Test #2:
score: -100
Wrong Answer
time: 3ms
memory: 3784kb
input:
5 1 1000000000 2 1000000000 3 -1000000000 4 -1000000000 5 -1000000000
output:
1 4
result:
wrong answer 2nd lines differ - expected: '5', found: '4 '