QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#83533#1863. Yes, Prime Ministerwoxiangbaile#AC ✓1667ms257248kbC++142.2kb2023-03-02 13:47:462023-03-02 13:47:48

Judging History

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

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2023-03-02 13:47:48]
  • 评测
  • 测评结果:AC
  • 用时:1667ms
  • 内存:257248kb
  • [2023-03-02 13:47:46]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;
#define rep(i, d, u) for(int i = d; i <= u; ++i)
#define dep(i, u, d) for(int i = u; i >= d; --i)
#define cep(n) while(n--)
#define gep(i, a) for(int i = firs[a]; i; i = neig[i])
int ured() {
	int re = 0;
	char ch;
	do {
		ch = getchar();
	} while('9' < ch || ch < '0');
	do {
		re = re * 10 + (ch ^ '0');
	} while('0' <= (ch = getchar()) && ch <= '9');
	return re;
}
int ired() {
	int re = 0;
	char ch;
	bool st = 0;
	do {
		ch = getchar();
	} while(('9' < ch || ch < '0') && ch != '-');
	if(ch == '-') {
		ch = getchar(), st = 1;
	}
	do {
		re = re * 10 + (ch ^ '0');
	} while('0' <= (ch = getchar()) && ch <= '9');
	return st ? -re : re;
}
void uwit(int da) {
	int ch[21], cn = 0;
	do {
		ch[++cn] = da - da / 10 * 10;
	} while(da /= 10);
	do {
		putchar('0' ^ ch[cn]);
	} while(--cn);
}
const int _maxn = 30000011, _maxa = 30000000;
struct node {
	int le, ri;
} arry[_maxn * 2];
bool operator<(node le, node ri) {
	return le . ri - le . le > ri . ri - ri . le;
}
priority_queue<node> queu;
int t, x[_maxn], mina[_maxn], prim[_maxn], coun, cnts, atpo, sran[_maxn], rans[_maxn];
bool visi[_maxn], pdif;
int main() {
	t = ured();
	rep(i, 1, t) {
		x[sran[i] = i] = ired();
	}
	rep(i, 2, _maxa) {
		if(!mina[i]) {
			mina[i] = prim[++coun] = i, visi[i] = 1;
		}
		for(int j = 1; j <= coun && i * prim[j] <= _maxa; ++j) {
			mina[i * prim[j]] = prim[j];
		}
	}
	rep(i, 1, _maxa) {
		if(visi[i]) {
			arry[++cnts] . le = i, arry[cnts] . ri = i, arry[++cnts] . le = -i + 1, arry[cnts] . ri = i;
		}
		if((i << 1 | 1) <= _maxa && visi[i << 1 | 1]) {
			arry[++cnts] . le = i, arry[cnts] . ri = i + 1, arry[++cnts] . le = -i + 1, arry[cnts] . ri = i + 1;
		}
	}
	sort(arry + 1, arry + cnts + 1, [](node le, node ri) {
		return le . le < ri . le;
	}), sort(sran + 1, sran + t + 1, [](int le, int ri) {
		return x[le] < x[ri];
	});
	rep(i, 1, t) {
		while(atpo + 1 <= cnts && arry[atpo + 1] . le <= x[sran[i]]) {
			queu . push(arry[++atpo]);
		}
		while(queu . top() . ri < x[sran[i]]) {
			queu . pop();
		}
		rans[sran[i]] = queu . top() . ri - queu . top() . le + 1;
	}
	rep(i, 1, t) {
		uwit(rans[i]), putchar('\n');
	}
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 1145ms
memory: 247796kb

input:

10
-2
-1
0
1
2
3
4
5
6
7

output:

6
4
3
2
1
1
2
1
2
1

result:

ok 10 numbers

Test #2:

score: 0
Accepted
time: 1173ms
memory: 247760kb

input:

201
-100
-99
-98
-97
-96
-95
-94
-93
-92
-91
-90
-89
-88
-87
-86
-85
-84
-83
-82
-81
-80
-79
-78
-77
-76
-75
-74
-73
-72
-71
-70
-69
-68
-67
-66
-65
-64
-63
-62
-61
-60
-59
-58
-57
-56
-55
-54
-53
-52
-51
-50
-49
-48
-47
-46
-45
-44
-43
-42
-41
-40
-39
-38
-37
-36
-35
-34
-33
-32
-31
-30
-29
-28
-27...

output:

202
202
199
197
194
193
191
191
191
191
191
181
178
178
178
173
173
173
166
166
163
163
158
157
157
157
151
149
146
146
142
142
139
137
134
134
131
131
127
127
122
122
118
118
118
113
113
109
106
106
103
101
101
97
94
94
94
89
86
86
82
82
79
79
74
73
71
71
67
67
62
61
58
58
58
53
53
53
46
46
43
41
3...

result:

ok 201 numbers

Test #3:

score: 0
Accepted
time: 1667ms
memory: 257248kb

input:

1000000
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
...

output:

2
1
1
2
1
2
1
2
2
2
1
2
1
2
2
2
1
2
1
2
2
2
1
2
53
2
2
58
1
2
1
67
2
2
2
2
1
79
2
2
1
2
1
2
2
94
1
2
2
2
2
2
1
2
2
2
2
118
1
122
1
127
2
2
2
2
1
2
2
2
1
146
1
2
2
2
157
2
1
163
2
2
1
2
173
2
2
178
1
2
2
191
191
191
2
2
1
2
2
2
1
206
1
211
2
2
1
218
1
223
2
2
1
2
2
2
2
239
2
2
2
251
251
251
2
2
1
2
2...

result:

ok 1000000 numbers