QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#661330#7804. Intersegment Activationucup-team1001#TL 0ms0kbC++202.3kb2024-10-20 15:49:382024-10-20 15:49:40

Judging History

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

  • [2024-10-20 15:49:40]
  • 评测
  • 测评结果:TL
  • 用时:0ms
  • 内存:0kb
  • [2024-10-20 15:49:38]
  • 提交

answer

#include "bits/stdc++.h"


using namespace std;
using i64 = long long;

const i64 mod = 1e9 + 7;
const i64 inf = 1e18;
//#define endl '\n'

i64 ask(int l, int t) {
    cout << l << " " << t << endl;
    i64 x;
    cin >> x;
    return x;
}

void solve() {
    int n;
    int sums;
    cin >> n >> sums;
    vector<int> show(n + 1, 0);
    auto check = [&](int k, int p) {
//        cerr << "check" << endl;
        if (k == 0)return;
        for (int i = 1; i <= n; i++) {
            if (show[i] == 0) {
                int t = ask(i, i);
                if (t != p) {
//                    cerr << i << endl;
                    show[i] = 1;
                    k--;
                    ask(i, i);
                }
                if (k == 0)return;
            }
        }
    };
    check(sums, sums);
    //获取所有的连续为0的区间
//   ;
    auto get = [&]() {
        vector<pair<int, int>> ans;
        for (int i = 1; i <= n; i++) {
            if (show[i] == 0) {
                int j = i;
                while (j <= n && show[j] == 0) {
                    j++;
                }
                ans.emplace_back(i, j - 1);
                i = j - 1;
            }
        }
//        cerr << "get" << endl;
//        for (auto [x, y]: ans) {
//            cerr << x << " " << y << endl;
//        }
        return ans;
    };
    vector<pair<int, int>> op;
    function<void(int, int)> dfs = [&](int l, int r) {
        if (l != r) {
            dfs(l, r - 1);
            auto z = op;
            op.emplace_back(l, r);
            for (auto [x, y]: z) {
                op.emplace_back(x, y);
            }
        }
        if (l == r) {
            op.emplace_back(l, r);
        }
    };
    auto x = get();
    while (!x.empty()) {
        auto [l, r] = x.back();
        op.clear();
//        cerr << "dfs " << l << " " << r << endl;
        dfs(l, r);

        for (auto [xx, yy]: op) {

            int t = ask(xx, yy);
            if (t == n)return;
            if (t != sums) {
                check(t - sums, t);
                x = get();
                sums = t;
                break;
            }
        }
    }


}

int main() {
//    ios::sync_with_stdio(false), cin.tie(0);
    int t = 1;
    while (t--) {
        solve();
    }
    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 0
Time Limit Exceeded

input:

3
0
0
0
1
0
1
1
2
3

output:

1 1
1 2
1 1
1 1
1 1
2 2
2 3
2 2
2 2

result: