QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#22767#2365. Flight CollisionDaBenZhongXiaSongKuaiDi#WA 71ms12776kbC++202.2kb2022-03-10 16:09:442022-04-30 01:38:41

Judging History

你现在查看的是最新测评结果

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2022-04-30 01:38:41]
  • 评测
  • 测评结果:WA
  • 用时:71ms
  • 内存:12776kb
  • [2022-03-10 16:09:44]
  • 提交

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()) 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;
}

詳細信息

Test #1:

score: 100
Accepted
time: 3ms
memory: 3780kb

input:

1
-4 13

output:

1
1 

result:

ok 2 lines

Test #2:

score: 0
Accepted
time: 2ms
memory: 3808kb

input:

5
1 1000000000
2 1000000000
3 -1000000000
4 -1000000000
5 -1000000000

output:

1
5 

result:

ok 2 lines

Test #3:

score: 0
Accepted
time: 2ms
memory: 3776kb

input:

3
-1000000000 1
999999999 0
1000000000 0

output:

1
3 

result:

ok 2 lines

Test #4:

score: 0
Accepted
time: 3ms
memory: 3816kb

input:

2
5 4
10 5

output:

2
1 2 

result:

ok 2 lines

Test #5:

score: 0
Accepted
time: 0ms
memory: 3668kb

input:

9
10 10
20 7
30 5
40 0
42 0
50 -1
60 -2
70 -10
80 -12

output:

1
1 

result:

ok 2 lines

Test #6:

score: 0
Accepted
time: 3ms
memory: 3868kb

input:

5
10 0
20 0
30 1
40 0
50 0

output:

3
1 2 5 

result:

ok 2 lines

Test #7:

score: 0
Accepted
time: 55ms
memory: 9136kb

input:

98765
0 -48539
1 -48539
2 -48539
3 -48539
4 -48539
5 -48539
6 -48539
7 -48539
8 -48539
9 -48539
10 -48539
11 -48539
12 -48539
13 -48539
14 -48539
15 -48539
16 -48539
17 -48539
18 -48539
19 -48539
20 -48539
21 -48539
22 -48539
23 -48539
24 -48539
25 -48539
26 -48539
27 -48539
28 -48539
29 -48539
30 -...

output:

98765
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 10...

result:

ok 2 lines

Test #8:

score: 0
Accepted
time: 71ms
memory: 12776kb

input:

99999
-999999396 999999395
-999971669 999999396
-999971668 -999999396
-999961260 999999396
-999961259 -999999396
-999907239 999999396
-999907238 -999999396
-999754561 999999396
-999754560 -999999396
-999662011 999999396
-999662010 -999999396
-999651505 999999396
-999651504 -999999396
-999619141 9999...

output:

1
99999 

result:

ok 2 lines

Test #9:

score: -100
Wrong Answer
time: 64ms
memory: 12752kb

input:

99999
-999999244 999999243
-999956299 999999244
-999956298 -999999244
-999945616 999999244
-999945615 -999999244
-999944410 999999244
-999944409 -999999244
-999891030 999999244
-999891029 -999999244
-999862261 999999244
-999862260 -999999244
-999835376 999999244
-999835375 -999999244
-999705681 9999...

output:

1
99999 

result:

wrong answer 2nd lines differ - expected: '1', found: '99999 '