QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#203754#5425. Proposition CompositionUrgantTeamTL 80ms10752kbC++232.0kb2023-10-06 20:06:512023-10-06 20:06:53

Judging History

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

  • [2023-10-06 20:06:53]
  • 评测
  • 测评结果:TL
  • 用时:80ms
  • 内存:10752kb
  • [2023-10-06 20:06:51]
  • 提交

answer

#include<bits/stdc++.h>

using namespace std;

typedef long long ll;
int const maxn = 25e4 + 5;
vector < int > L[maxn];
int add[maxn], ok[maxn];

main() {
#ifdef HOME
    freopen("input.txt", "r", stdin);
#endif // HOME
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int t;
    cin >> t;
    while (t--) {
        int n, m, u, v;
        cin >> n >> m;
        for (int i = 1; i <= n; i++) L[i] = {}, add[i] = 0;
        for (int M = 1; M <= m; M++) {
            cin >> u >> v;
            if (u > v) swap(u, v);
            L[u].push_back(v);
            add[u]++, add[v]--;
            ll ans = 0;
            int bal = 0;
            for (int i = 1; i < n; i++) {
                bal += add[i];
                if (bal == 0) ans += M;
                else if (bal == 1) ans++;
                if (!bal) ok[i] = 1;
                else ok[i] = 0;
            }
            bal = 0;
            for (int i = 1; i < n; i++) {
                bal += add[i];
                if (bal == 0) {
                    ans += (n - i - 1);
                    continue;
                }
                int imin = n + 1, imax = -1;
                for (int j = 1; j <= i; j++) {
                    for (auto key : L[j]) {
                        if (key >= i + 1) {
                            imin = min(imin, key);
                            imax = max(imax, key);
                        }
                    }
                }
                for (int j = i + 1; j < imin; j++) {
                    int flag = 0;
                    for (int pos = i + 1; pos <= j; pos++) {
                        for (auto key : L[pos]) {
                            if (key >= j + 1) flag = 1;
                        }
                    }
                    ans += !flag;
                }
                for (int j = imax; j < n; j++) {
                    ans += ok[j];
                }
            }
            cout << ans << '\n';
        }
    }
    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

input:

3
4 3
2 4
4 2
3 3
7 3
3 4
1 2
1 7
6 4
1 3
4 6
2 5
3 4

output:

6
5
6
21
24
10
15
12
3
2

result:

ok 10 numbers

Test #2:

score: 0
Accepted
time: 80ms
memory: 10752kb

input:

45540
10 9
10 1
1 10
10 1
1 10
1 10
10 1
1 10
3 3
10 1
10 4
1 2
1 10
3 4
1 10
7 6
7 1
5 6
1 7
6 6
7 1
6 7
9 7
3 3
7 7
5 4
1 1
9 1
9 1
6 5
8 7
1 8
4 4
5 6
1 1
1 8
6 6
4 5
3 3
3 2
3 1
3 3
3 9
3 1
3 3
2 2
3 3
3 1
2 2
1 1
2 3
3 1
10 1
2 1
7 1
1 7
3 8
1 3
1 3
3 3
1 3
2 2
1 3
1 3
3 3
3 6
3 1
1 3
1 3
1 3
1...

output:

45
36
36
36
36
36
36
36
36
45
36
28
21
21
15
10
10
10
6
36
44
50
57
28
21
15
28
28
21
21
15
15
10
3
1
1
3
3
3
3
1
1
1
0
0
45
21
3
1
1
1
1
1
1
1
3
1
1
1
1
1
45
36
36
36
36
36
36
36
3
3
1
0
0
0
0
0
0
3
1
0
0
15
10
10
0
0
0
0
0
0
0
0
28
34
21
6
6
6
6
1
0
0
21
15
15
0
0
0
0
0
0
0
45
53
0
0
0
0
0
0
0
0
1...

result:

ok 249586 numbers

Test #3:

score: -100
Time Limit Exceeded

input:

2507
86 4
41 41
36 36
31 30
86 1
110 22
1 110
110 1
11 11
110 1
110 1
110 1
1 110
107 106
72 72
106 106
74 74
1 110
110 1
58 58
110 1
110 1
1 110
101 100
110 1
100 100
110 1
8 7
114 180
114 1
114 1
114 1
1 114
1 114
114 1
37 38
49 48
105 106
1 114
90 90
1 114
9 9
114 1
67 68
20 20
114 1
1 114
54 55
...

output:

3655
3740
3823
3570
5995
5886
5886
5886
5886
5886
5886
5778
5778
5778
5778
5778
5778
5778
5778
5778
5778
5671
5671
5671
5671
5565
6441
6328
6328
6328
6328
6328
6216
6105
5995
5995
5995
5995
5995
5995
5886
5886
5886
5886
5778
5671
5671
5565
5565
5460
5460
5460
5460
5460
5356
5253
5253
5253
5151
5151
...

result: