File size: 3,211 Bytes
1fd0050
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
#include "testlib.h"
#include <vector>
#include <string>
#include <cmath>

namespace {
    constexpr int MAX_N = (int)1E5 + 10, SINGLE_QUERY_LIM = (int)1E7,
                  TOTAL_ROUND_LIM = (int)1E7, TOTAL_QUERY_LIM = (int)3E8;
    int subtask, n;
    int cnt_query, cnt_round;
    int inter[SINGLE_QUERY_LIM+10];
    
    // Helper to ensure conditions and quit if they fail
    void Ensure(bool condition, const char* fail_message) {
        if (!condition){
            quitf(_wa, fail_message);
        }
    }

    int p[MAX_N], q[MAX_N], vis[MAX_N], an;
    
    int flip(int u) {
        u = q[u];
        if (vis[u] ^= 1) {
            an += vis[u - 1] + vis[u + 1];
        } else {
            an -= vis[u - 1] + vis[u + 1];
        }
        return an || (vis[1] && vis[n]);
    }
    
    bool check(int c1[], int c2[]) {
        int opt = -1;
        for (int i = 0; i < n; i++)
            if (c1[i] == c2[0]) {
                opt = i;
                break;
            }
        if (opt == -1) return false;
        
        bool f1 = true, f2 = true;
        for (int i = 1, op1 = opt, op2 = opt; i < n; i++) {
            op1++; op2--;
            if (op1 >= n) op1 -= n;
            if (op2 < 0) op2 += n;
            if (c1[op1] != c2[i]) f1 = false;
            if (c1[op2] != c2[i]) f2 = false;
            if ((!f1) && (!f2)) return false;
        }
        return true;
    }

    double f(double x) {
        return std::min(std::max(std::log2(x), 0.0), 8.0);
    }
    
    double lambda(int t, int Q) {
        return std::max(0.0, 1 - 0.1 * (f(t / 18.0) + f(Q / 1.5E7)));
    }

} // namespace

void input_inter(int N){
    for(int i = 0; i < N; i++)
        inter[i] = ouf.readInt();
}

void output_inter(const int N){
    std::vector<int> temp_vec;
    for (int i=0; i<N; ++i) temp_vec.push_back(inter[i]);
    println(temp_vec);
}

void query(const int N) {
    for (int i = 0; i < N; i++) {
        int u = inter[i];
        Ensure(1 <= u && u <= n, "Query value out of range [1, n]");
        inter[i] = flip(u);
    }
    output_inter(N);
}

int main(int argc, char* argv[]) {
    registerInteraction(argc, argv);
    subtask = inf.readInt();
    n = inf.readInt();
    for (int i = 0; i < n; i++) {
        p[i] = ans.readInt();
        q[p[i]] = i + 1;
    }

    inter[0] = subtask;
    inter[1] = n;
    output_inter(2);
    
    int N;
    while (true) {
        N = ouf.readInt();
        if (N == -1) {
            input_inter(n);
            Ensure(check(p, inter), "Final answer is incorrect.");
            break;
        } else {
            Ensure(N <= SINGLE_QUERY_LIM, "Single query size limit exceeded.");
            cnt_round += 1;
            cnt_query += N;
            Ensure(cnt_round <= TOTAL_ROUND_LIM, "Total round limit exceeded.");
            Ensure(cnt_query <= TOTAL_QUERY_LIM, "Total query limit exceeded.");
            input_inter(N);
            query(N);
        }
    }
    
    double score_ratio = lambda(cnt_round, cnt_query);
    
    // Use quitp with a formatted message that includes the "Ratio:" tag
    quitp(score_ratio, "Correct. Rounds: %d, Queries: %d. Ratio: %.4f", cnt_round, cnt_query, score_ratio);
    
    return 0;
}