#include<bits/stdc++.h>
#include "xylophone.h"
#define int long long
using namespace std;
/*int query(int l, int r)
{
cout<<"? "<<l<<" "<<r<<endl;
int x; cin>>x;
return x;
}
void answer(int p, int v)
{
cout<<"! "<<p<<" "<<v<<endl;
}*/
void solve(int32_t n)
{
vector<int> a(n+1), s(n+1);
a[2] = query(1, 2), s[2] = 0;
int last = a[2];
for(int i = 3; i <= n; i++){
int cur = query(i-1, i), sum = query(i-2, i);
a[i] = cur;
if(last + cur == sum) s[i] = s[i-1];
else s[i] = (s[i-1] ^ 1);
last = cur;
}
vector<int> cd(n+1);
for(int i = 1; i <= n; i++) cd[i] = cd[i-1] + a[i] * (-s[i] * 2 + 1);
int maxplace = 1, minplace = 1;
for(int i = 1; i <= n; i++){
if(cd[maxplace] < cd[i]) maxplace = i;
if(cd[minplace] > cd[i]) minplace = i;
}
if(maxplace < minplace){
for(int i = 1; i <= n; i++) s[i] ^= 1;
for(int i = 1; i <= n; i++) cd[i] = cd[i-1] + a[i] * (-s[i] * 2 + 1);
}
int minval = 1e18;
for(int i = 1; i <= n; i++) minval = min(minval, cd[i]);
for(int i = 1; i <= n; i++) cd[i] += -minval + 1;
for(int i = 1; i <= n; i++) answer(i, cd[i]);
}
/*signed main()
{
solve(5);
}*/
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
1 ms |
344 KB |
Output is correct |
3 |
Correct |
1 ms |
344 KB |
Output is correct |
4 |
Correct |
2 ms |
344 KB |
Output is correct |
5 |
Correct |
2 ms |
344 KB |
Output is correct |
6 |
Correct |
1 ms |
344 KB |
Output is correct |
7 |
Correct |
1 ms |
344 KB |
Output is correct |
8 |
Correct |
1 ms |
344 KB |
Output is correct |
9 |
Correct |
1 ms |
344 KB |
Output is correct |
10 |
Correct |
1 ms |
344 KB |
Output is correct |
11 |
Correct |
1 ms |
340 KB |
Output is correct |
12 |
Correct |
1 ms |
432 KB |
Output is correct |
13 |
Correct |
1 ms |
344 KB |
Output is correct |
14 |
Correct |
1 ms |
436 KB |
Output is correct |
15 |
Correct |
1 ms |
436 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
1 ms |
344 KB |
Output is correct |
3 |
Correct |
1 ms |
344 KB |
Output is correct |
4 |
Correct |
2 ms |
344 KB |
Output is correct |
5 |
Correct |
2 ms |
344 KB |
Output is correct |
6 |
Correct |
1 ms |
344 KB |
Output is correct |
7 |
Correct |
1 ms |
344 KB |
Output is correct |
8 |
Correct |
1 ms |
344 KB |
Output is correct |
9 |
Correct |
1 ms |
344 KB |
Output is correct |
10 |
Correct |
1 ms |
344 KB |
Output is correct |
11 |
Correct |
1 ms |
340 KB |
Output is correct |
12 |
Correct |
1 ms |
432 KB |
Output is correct |
13 |
Correct |
1 ms |
344 KB |
Output is correct |
14 |
Correct |
1 ms |
436 KB |
Output is correct |
15 |
Correct |
1 ms |
436 KB |
Output is correct |
16 |
Correct |
2 ms |
344 KB |
Output is correct |
17 |
Correct |
5 ms |
440 KB |
Output is correct |
18 |
Correct |
8 ms |
344 KB |
Output is correct |
19 |
Correct |
9 ms |
452 KB |
Output is correct |
20 |
Correct |
9 ms |
448 KB |
Output is correct |
21 |
Correct |
7 ms |
344 KB |
Output is correct |
22 |
Correct |
11 ms |
592 KB |
Output is correct |
23 |
Correct |
11 ms |
344 KB |
Output is correct |
24 |
Correct |
8 ms |
344 KB |
Output is correct |
25 |
Correct |
10 ms |
344 KB |
Output is correct |
26 |
Correct |
10 ms |
344 KB |
Output is correct |
27 |
Correct |
9 ms |
452 KB |
Output is correct |
28 |
Correct |
9 ms |
456 KB |
Output is correct |
29 |
Correct |
9 ms |
456 KB |
Output is correct |
30 |
Correct |
9 ms |
344 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
1 ms |
344 KB |
Output is correct |
3 |
Correct |
1 ms |
344 KB |
Output is correct |
4 |
Correct |
2 ms |
344 KB |
Output is correct |
5 |
Correct |
2 ms |
344 KB |
Output is correct |
6 |
Correct |
1 ms |
344 KB |
Output is correct |
7 |
Correct |
1 ms |
344 KB |
Output is correct |
8 |
Correct |
1 ms |
344 KB |
Output is correct |
9 |
Correct |
1 ms |
344 KB |
Output is correct |
10 |
Correct |
1 ms |
344 KB |
Output is correct |
11 |
Correct |
1 ms |
340 KB |
Output is correct |
12 |
Correct |
1 ms |
432 KB |
Output is correct |
13 |
Correct |
1 ms |
344 KB |
Output is correct |
14 |
Correct |
1 ms |
436 KB |
Output is correct |
15 |
Correct |
1 ms |
436 KB |
Output is correct |
16 |
Correct |
2 ms |
344 KB |
Output is correct |
17 |
Correct |
5 ms |
440 KB |
Output is correct |
18 |
Correct |
8 ms |
344 KB |
Output is correct |
19 |
Correct |
9 ms |
452 KB |
Output is correct |
20 |
Correct |
9 ms |
448 KB |
Output is correct |
21 |
Correct |
7 ms |
344 KB |
Output is correct |
22 |
Correct |
11 ms |
592 KB |
Output is correct |
23 |
Correct |
11 ms |
344 KB |
Output is correct |
24 |
Correct |
8 ms |
344 KB |
Output is correct |
25 |
Correct |
10 ms |
344 KB |
Output is correct |
26 |
Correct |
10 ms |
344 KB |
Output is correct |
27 |
Correct |
9 ms |
452 KB |
Output is correct |
28 |
Correct |
9 ms |
456 KB |
Output is correct |
29 |
Correct |
9 ms |
456 KB |
Output is correct |
30 |
Correct |
9 ms |
344 KB |
Output is correct |
31 |
Correct |
20 ms |
344 KB |
Output is correct |
32 |
Correct |
30 ms |
460 KB |
Output is correct |
33 |
Correct |
48 ms |
484 KB |
Output is correct |
34 |
Correct |
68 ms |
492 KB |
Output is correct |
35 |
Correct |
44 ms |
492 KB |
Output is correct |
36 |
Correct |
50 ms |
488 KB |
Output is correct |
37 |
Correct |
54 ms |
592 KB |
Output is correct |
38 |
Correct |
55 ms |
592 KB |
Output is correct |
39 |
Correct |
59 ms |
488 KB |
Output is correct |
40 |
Correct |
39 ms |
344 KB |
Output is correct |
41 |
Correct |
39 ms |
344 KB |
Output is correct |
42 |
Correct |
39 ms |
592 KB |
Output is correct |
43 |
Correct |
53 ms |
488 KB |
Output is correct |
44 |
Correct |
50 ms |
492 KB |
Output is correct |
45 |
Correct |
46 ms |
496 KB |
Output is correct |
46 |
Correct |
50 ms |
492 KB |
Output is correct |
47 |
Correct |
48 ms |
344 KB |
Output is correct |
48 |
Correct |
47 ms |
344 KB |
Output is correct |
49 |
Correct |
62 ms |
488 KB |
Output is correct |
50 |
Correct |
62 ms |
592 KB |
Output is correct |
51 |
Correct |
50 ms |
592 KB |
Output is correct |
52 |
Correct |
54 ms |
504 KB |
Output is correct |
53 |
Correct |
61 ms |
496 KB |
Output is correct |
54 |
Correct |
50 ms |
488 KB |
Output is correct |
55 |
Correct |
51 ms |
496 KB |
Output is correct |
56 |
Correct |
59 ms |
508 KB |
Output is correct |
57 |
Correct |
58 ms |
492 KB |
Output is correct |
58 |
Correct |
61 ms |
492 KB |
Output is correct |
59 |
Correct |
52 ms |
344 KB |
Output is correct |
60 |
Correct |
48 ms |
488 KB |
Output is correct |