QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#488841#8819. CNOI Knowledgedalao_see_meTL 0ms5868kbC++141.2kb2024-07-24 15:42:272024-07-24 15:42:27

Judging History

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

  • [2024-07-24 15:42:27]
  • 评测
  • 测评结果:TL
  • 用时:0ms
  • 内存:5868kb
  • [2024-07-24 15:42:27]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;
int read() {
    int x = 0, f = 1; char c = getchar();
    while (c < '0' || c > '9') {if (c == '-') f = -f; c = getchar();}
    while (c >= '0' && c <= '9') {x = x * 10 + (c ^ 48); c = getchar();}
    return x * f;
}
const int N = 1005;
int n;
int a[N][N], b[N];
int ask(int l, int r) {
    if (~a[l][r]) return a[l][r];
    printf("? %d %d\n", l, r); fflush(stdout);
    return a[l][r] = read();
}
void Solve() {
    n = read();
    for (int i = 1; i <= n; i++)
        for (int j = 1; j <= n; j++)
            a[i][j] = -1;
    for (int i = 1; i <= n; i++) a[i][i - 1] = 0;
    int tot = 0;
    for (int i = 1; i <= n; i++) {
        int L = 0, R = i - 1;
        while (L < R) {
            int mid = L + R + 1 >> 1;
            if (ask(mid, i) - ask(mid, i - 1) < i - mid + 1) L = mid;
            else R = mid - 1;
        }
        if (L) b[i] = b[L];
        else b[i] = ++tot;
    }
    putchar('!');
    for (int i = 1; i <= n; i++) printf(" %d", b[i]); putchar('\n');
}
int main() {
    // freopen(".in", "r", stdin);
    // freopen(".out", "w", stdout);
    int _ = 1;
    while (_--) Solve();
    return 0;
}

詳細信息

Test #1:

score: 100
Accepted
time: 0ms
memory: 5868kb

input:

12
3
1
6
6
3
10
10
15
10
6
21
15
27
20
15
14
10
6
3
9
6
20
34
26
43
34
19
14
9
6
5
3
2
1
25
8
5
25
19
9
19
13

output:

? 1 2
? 1 1
? 1 3
? 2 4
? 2 3
? 1 4
? 2 5
? 1 5
? 3 6
? 3 5
? 1 6
? 3 7
? 1 7
? 2 7
? 2 6
? 4 8
? 4 7
? 6 8
? 6 7
? 5 8
? 5 7
? 4 9
? 2 9
? 2 8
? 1 9
? 1 8
? 5 10
? 5 9
? 7 10
? 7 9
? 8 10
? 8 9
? 9 10
? 9 9
? 5 11
? 8 11
? 9 11
? 6 12
? 6 11
? 9 12
? 7 12
? 7 11
! 1 2 3 4 5 6 2 5 7 7 5 6

result:

ok Accepted. 42 queries used.

Test #2:

score: -100
Time Limit Exceeded

input:

1000
3
1
5
2
1
3
2
1
7
11
7
8
5
5
3
2
1
11
3
2
1
11
7
5
7
15
8
5
3
3
1
15
11
8
5
2
1
19
7
3
2
1
19
15
4
3
2
1
23
5
3
2
1
20
17
5
4
3
2
1
23
5
4
3
2
1
23
15
9
4
13
6
15
7
31
14
8
5
5
3
3
1
31
23
15
11
7
5
3
1
41
16
11
8
5
2
1
45
36
15
11
7
3
2
1
55
20
7
15
11
11
58
48
21
8
5
5
3
2
1
68
21
16
8
5
69
5...

output:

? 1 2
? 1 1
? 1 3
? 2 3
? 2 2
? 2 4
? 3 4
? 3 3
? 2 5
? 1 5
? 1 4
? 3 6
? 3 5
? 4 6
? 4 5
? 5 6
? 5 5
? 3 7
? 5 7
? 6 7
? 6 6
? 4 8
? 4 7
? 6 8
? 5 8
? 4 9
? 6 9
? 7 9
? 7 8
? 8 9
? 8 8
? 5 10
? 5 9
? 7 10
? 8 10
? 9 10
? 9 9
? 5 11
? 8 11
? 9 11
? 10 11
? 10 10
? 6 12
? 6 11
? 9 12
? 10 12
? 11 12
...

result: