QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#63943#5110. SplitstreamNoobie_99WA 9ms6436kbC++202.5kb2022-11-23 19:31:002022-11-23 19:31:02

Judging History

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

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2022-11-23 19:31:02]
  • 评测
  • 测评结果:WA
  • 用时:9ms
  • 内存:6436kb
  • [2022-11-23 19:31:00]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define debug(x) cerr << "[" << __LINE__ << ' ' << #x << "]: " << (x) << endl

int main() {
    cin.tie(0)->sync_with_stdio(0);

    int m, n, q;
    cin >> m >> n >> q;

    vector<vector<int>> g(n + 3*n+1);
    vector<vector<int>> g2(n + 3*n+1);
    vector<int> deg(4*n+1);
    for (int i=0; i<n; i++) {
        char c;
        int x, y, z;
        cin >> c >> x >> y >> z;
        if (c == 'S') {
            g[n+x].push_back(i);
            g[i].push_back(n+y);
            g[i].push_back(n+z);
            g2[i].push_back(n+x);
            g2[n+y].push_back(i);
            g2[n+z].push_back(i);
            deg[i]++;
            deg[n+y]++;
            deg[n+z]++;
        } else {
            g[n+x].push_back(i);
            g[n+y].push_back(i);
            g[i].push_back(n+z);
            g2[i].push_back(n+x);
            g2[i].push_back(n+y);
            g2[n+z].push_back(i);
            deg[i] += 2;
            deg[n+z]++;
        }
    }

    vector<int> topo;
    for (int i=0; i<4*n+1; i++) if (deg[i] == 0) topo.push_back(i);

    vector<int> sz(g.size());
    sz[n+1] = m;
    for (int i=0; i<(int)topo.size(); i++) {
        int e = topo[i];
        if (g[e].size() == 0) continue;
        if (g[e].size() == 1) sz[g[e][0]] += sz[e];
        else {
            sz[g[e][0]] += (sz[e]+1) / 2;
            sz[g[e][1]] += (sz[e]) / 2;
        }

        for (int f : g[e]) {
            deg[f]--;
            if (deg[f] == 0) topo.push_back(f);
        }
    }

    while (q--) {
        int x, k;
        cin >> x >> k;
        if (sz[n+x] < k) {
            cout << "none\n";
            continue;
        }

        int cur = n+x;
        while (cur != n+1) {
            if (g2[cur].size() == 2) {
                int a = g2[cur][0], b = g2[cur][1];
                int mn = min(sz[a], sz[b]);
                if (2 * mn >= k) {
                    if (k % 2 == 1) k = (k+1)/2, cur = a;
                    else k /= 2, cur = b;
                } else {
                    k -= mn;
                    if (a > mn) cur = a;
                    else cur = b;
                }
            } else {
                int par = g2[cur][0];
                if (g[par].size() == 2) {
                    k *= 2;
                    if (cur == g[par][0]) k--;
                }
                cur = par;
            }
        }
        cout << k << '\n';
    }
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 1ms
memory: 3264kb

input:

5 8 26
M 8 9 13
S 2 4 5
S 1 2 3
M 6 5 8
S 4 9 10
S 10 14 15
S 3 6 7
S 7 11 12
2 3
2 4
3 2
3 3
4 2
4 3
5 1
5 2
6 1
6 2
7 1
7 2
8 2
8 3
9 1
9 2
10 1
10 2
11 1
11 2
12 1
13 3
13 4
14 1
14 2
15 1

output:

5
none
4
none
5
none
3
none
2
none
4
none
3
none
1
none
5
none
4
none
none
3
none
5
none
none

result:

ok 26 lines

Test #2:

score: 0
Accepted
time: 5ms
memory: 6436kb

input:

1000000000 8191 1000
S 1 2 3
S 2 4 5
S 3 6 7
S 4 8 9
S 5 10 11
S 6 12 13
S 7 14 15
S 8 16 17
S 9 18 19
S 10 20 21
S 11 22 23
S 12 24 25
S 13 26 27
S 14 28 29
S 15 30 31
S 16 32 33
S 17 34 35
S 18 36 37
S 19 38 39
S 20 40 41
S 21 42 43
S 22 44 45
S 23 46 47
S 24 48 49
S 25 50 51
S 26 52 53
S 27 54 55...

output:

1
3
999999999
499999999
333333331
999999997
499999997
333333329
2
4
1000000000
500000000
333333332
999999998
499999998
333333330
1
5
999999997
499999997
333333329
999999993
499999993
333333325
3
7
999999999
499999999
333333331
999999995
499999995
333333327
2
6
999999998
499999998
333333330
999999994...

result:

ok 1000 lines

Test #3:

score: -100
Wrong Answer
time: 9ms
memory: 6264kb

input:

1000000000 8190 1000
S 1 2 3
M 8193 8194 8192
S 2 4 5
M 8195 8196 8193
S 3 6 7
M 8197 8198 8194
S 4 8 9
M 8199 8200 8195
S 5 10 11
M 8201 8202 8196
S 6 12 13
M 8203 8204 8197
S 7 14 15
M 8205 8206 8198
S 8 16 17
M 8207 8208 8199
S 9 18 19
M 8209 8210 8200
S 10 20 21
M 8211 8212 8201
S 11 22 23
M 821...

output:

1
2
1000005632
500000000
333333333
1000005631
499999999
333333332
1
1
3
3
999999999
1000005631
499999999
499999999
333333331
333333331
999999997
1000005629
499999997
499999997
333333329
333333329
2
2
4
4
1000000000
1000005632
500000000
500000000
333333332
333333332
999999998
1000005630
499999998
499...

result:

wrong answer 3rd lines differ - expected: '1000000000', found: '1000005632'