QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#748140#9731. Fuzzy RankinginfCraftTL 1660ms17156kbC++174.0kb2024-11-14 19:28:172024-11-14 19:28:25

Judging History

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

  • [2024-11-25 12:28:53]
  • hack成功,自动添加数据
  • (/hack/1257)
  • [2024-11-14 19:28:25]
  • 评测
  • 测评结果:TL
  • 用时:1660ms
  • 内存:17156kb
  • [2024-11-14 19:28:17]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;
#define endl '\n'
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define pb push_back

#define Yes cout << "Yes\n"
#define No cout << "No\n"
#define YES cout << "YES\n"
#define NO cout << "NO\n"
#define ff first
#define ss second
#define fori(x,y) for(int i=x;i<=(int)(y);++i)
#define forj(x,y) for(int j=x;j<=(int)(y);++j)
#define fork(x,y) for(int k=x;k<=(int)(y);++k)

#define debug(x) cerr << #x << " = " << x << endl

typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

ll MOD = 998244353;
ll qpow(ll a,ll p) {ll res=1; while(p) {if (p&1) {res=res*a%MOD;} a=a*a%MOD; p>>=1;} return res;}

struct Block {
    int n, t;
    vector<int> st, ed;
    vector<int> pos, arr;
    vector<map<int,ll>> maps;
    // 上面一组长度为t,下面一组长度为n
    Block(int n): n(n) {
        int m = sqrt(n);  // 块大小
        t = n/m;  // 分块中块的数量
        if (n%m) t++;  // 不是整除,最后有一个小碎块
        
        st = ed = vector<int>(t+1, 0);
        maps = vector<map<int,ll>>(t+1, map<int,ll>());
        pos = arr = vector<int>(n+1, 0);
        fori(1, t) {
            st[i] = (i-1)*m+1;
            ed[i] = i*m;
        }
        ed[t] = n;  // 最后一块
        fori(1, n) pos[i] = (i-1)/m+1;
    }
    
    void init() {
        fori(1, n) maps[pos[i]][arr[i]]++;
    }
    /**
     * 查询区间和
     */
    map<int,ll> query(int L, int R) {
        if (L>R) return map<int,ll>();
        int p = pos[L], q = pos[R];
        
        map<int,ll> res;
        if (p == q) {
            fori(L, R) res[arr[i]]++;
            return res;
        }
        fori(p+1, q-1) for (auto [x, y]: maps[i]) res[x] += y;
        fori(L, ed[p]) res[arr[i]]++;
        fori(st[q], R) res[arr[i]]++;
        return res;
    }
};

void solve() {
	int n, m, q;
    cin >> n >> m >> q;
    vector<vector<int>> g(n+1, vector<int>());
    vector<vector<int>> rnk(m+1, vector<int>(n+1, 0));
    fori(1, m) {
        forj(1, n) cin >> rnk[i][j];
        forj(1, n-1) g[rnk[i][j]].push_back(rnk[i][j+1]);
    }

    vector<int> scc(n+1, 0), low(n+1, 0), num(n+1, 0);
    int dfn = 0, cnt = 0;  // dfn为访问序号,cnt记录强连通分量的个数和编号
    stack<int> st;  // 用于保存属于同一个强连通分量的点

    auto dfs = [&](auto self, int u) -> void {
        st.push(u);
        low[u] = num[u] = ++dfn;  // 初始化
        fori(0, g[u].size()-1) {
            int v = g[u][i];
            if (!num[v]) {  // 如果没有访问过
                self(self, v);
                low[u] = min(low[u], low[v]);  // 递归返回子节点的low
            }
            else if (!scc[v]) {  // 如果子节点v访问过且不属于某一个强连通分量(好像直接else不加判断也可以)
                low[u] = min(low[u], num[v]);  // 该点的序号
            }
        }
        if (low[u] == num[u]) {  // 栈底:scc祖先
            cnt++;  // 这是一个新的强连通分量
            while (1) {
                int v = st.top();
                st.pop();
                scc[v] = cnt;  // 记录编号
                if (v == u) break;  // 栈底为该强连通分量的祖先节点
            }
        }
    };
    fori(1, n) if (!num[i]) dfs(dfs, i);

    vector<Block> vec;
    fori(1, m) {
        Block b(n);
        forj(1, n) b.arr[j] = scc[rnk[i][j]];
        b.init();
        vec.push_back(b);
    }

    ll lastans = 0;
    while (q--) {
        int id, l, r;
        cin >> id >> l >> r;
        id = (id+lastans)%m+1;
        l = (l+lastans)%n+1;
        r = (r+lastans)%n+1;

        map<int,ll> maps = vec[id-1].query(l, r);
        ll ans = 0;
        for (auto [x, y]: maps) ans += y*(y-1)/2;
        cout << ans << endl;
        lastans = ans;
    }

}

signed main() {
	IOS;
	int t;
	cin >> t;
	while (t--) {
		solve();
	}
	return 0;
}

详细

Test #1:

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

input:

2
5 2 2
1 2 3 4 5
5 4 3 2 1
1 0 2
1 2 1
5 3 3
1 2 3 4 5
1 3 2 4 5
1 2 3 5 4
0 0 2
0 2 3
1 0 3

output:

3
10
1
1
2

result:

ok 5 lines

Test #2:

score: 0
Accepted
time: 31ms
memory: 3672kb

input:

2000
10 10 10
4 5 3 6 8 9 2 1 7 10
4 5 6 3 8 9 1 2 10 7
5 4 3 6 8 9 1 2 7 10
4 5 6 3 8 9 1 2 7 10
4 5 3 6 8 9 2 1 10 7
4 5 6 3 8 9 1 2 10 7
5 4 6 3 8 9 1 2 7 10
5 4 6 3 8 9 1 2 10 7
4 5 6 3 8 9 2 1 7 10
5 4 3 6 8 9 2 1 10 7
3 1 6
5 7 8
0 2 3
7 9 9
2 1 9
6 1 6
7 2 3
0 0 4
1 8 1
1 8 7
10 10 10
9 10 5 ...

output:

1
1
0
0
3
2
0
2
2
4
1
0
1
1
1
1
2
4
4
3
1
6
28
0
0
10
10
6
6
15
0
3
10
6
16
6
11
1
2
1
1
6
3
3
0
4
5
3
4
1
1
3
2
4
0
3
4
4
4
4
0
0
1
1
2
0
0
1
2
1
1
0
0
1
4
3
0
4
4
1
3
6
16
16
0
11
16
1
4
15
1
4
2
0
0
2
0
1
2
4
0
0
0
0
0
0
0
0
0
0
1
0
0
6
3
0
3
4
0
0
0
0
0
0
0
0
0
0
0
0
3
0
0
1
3
1
0
0
3
3
9
1
9
4
...

result:

ok 20000 lines

Test #3:

score: 0
Accepted
time: 49ms
memory: 3796kb

input:

8000
5 5 10
3 5 2 4 1
3 2 5 4 1
3 5 2 4 1
3 5 2 4 1
3 5 2 4 1
1 1 1
4 1 3
1 0 3
4 2 3
1 0 1
3 2 3
1 2 3
3 0 2
1 1 3
1 1 2
5 5 10
5 3 1 2 4
3 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
0
0
0
0
0
6
0
0
10
1
0
0
0
1
2
1
1
0
0
0
1
1
1
0
0
1
0
1
1
0
1
3
0
0
0
3
1
0
10
0
4
0
0
2...

result:

ok 40000 lines

Test #5:

score: 0
Accepted
time: 105ms
memory: 3840kb

input:

2000
1 100 100
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
25 0 0
9 0 0
80 0 0
37 0 0
18 0 0
24 0 0
5 0 0
87 0 0
50 0 0
63 0 0
53 0 0
62 0 0
37 ...

output:

0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
...

result:

ok 200000 lines

Test #6:

score: 0
Accepted
time: 28ms
memory: 5404kb

input:

10
20 1000 2000
2 5 1 3 12 16 14 15 7 4 19 13 18 10 20 9 11 8 6 17
5 2 12 1 16 3 19 4 7 15 14 18 13 10 9 20 11 8 6 17
2 5 1 16 12 3 7 14 4 19 15 13 18 10 20 9 11 17 6 8
2 5 1 16 3 12 15 7 4 14 19 18 13 10 9 20 11 8 6 17
5 2 3 12 1 16 14 7 4 15 19 18 13 10 20 9 11 6 17 8
2 5 3 1 12 16 19 15 7 4 14 18...

output:

11
0
11
10
1
11
5
10
10
5
13
2
0
18
2
14
2
18
10
13
1
1
0
1
4
7
6
0
15
11
1
4
6
19
3
9
3
1
0
20
2
16
1
0
3
2
3
0
18
1
17
1
1
8
1
5
17
1
3
6
1
2
15
15
2
1
0
3
18
22
0
1
2
15
13
12
20
3
0
9
15
1
4
17
22
16
8
6
13
0
7
11
15
19
15
6
7
10
17
12
9
1
11
1
0
4
6
17
1
17
6
5
1
1
16
14
3
1
12
18
1
0
18
12
17
...

result:

ok 20000 lines

Test #7:

score: 0
Accepted
time: 44ms
memory: 4624kb

input:

33
3 2000 2000
1 2 3
2 1 3
2 1 3
2 1 3
1 2 3
2 1 3
2 1 3
1 2 3
2 1 3
1 2 3
2 1 3
2 1 3
2 1 3
1 2 3
2 1 3
2 1 3
2 1 3
1 2 3
2 1 3
2 1 3
1 2 3
1 2 3
2 1 3
1 2 3
2 1 3
1 2 3
2 1 3
1 2 3
2 1 3
2 1 3
1 2 3
2 1 3
2 1 3
2 1 3
1 2 3
2 1 3
1 2 3
1 2 3
2 1 3
1 2 3
1 2 3
1 2 3
1 2 3
2 1 3
2 1 3
1 2 3
2 1 3
2 1...

output:

1
1
0
1
0
0
1
0
0
0
0
0
0
1
1
0
0
0
1
1
0
0
0
0
1
0
1
0
0
0
0
1
0
0
1
0
1
0
0
0
1
0
1
0
0
0
0
1
0
0
1
1
0
1
0
0
1
0
1
1
0
0
0
1
1
0
1
1
0
1
0
1
0
0
0
1
0
0
0
1
1
1
1
0
0
0
1
0
1
0
0
0
0
1
1
0
0
1
1
1
0
1
1
0
0
1
0
0
0
0
1
0
0
0
0
0
0
0
1
1
1
0
0
0
0
1
0
1
0
1
0
0
0
1
1
1
0
0
0
0
0
0
0
0
0
0
1
1
0
0
...

result:

ok 66000 lines

Test #8:

score: 0
Accepted
time: 184ms
memory: 5232kb

input:

10
100 200 20000
33 77 70 12 88 3 29 59 63 41 75 18 42 83 96 44 67 73 79 48 92 54 78 93 21 14 24 72 91 25 71 97 2 89 76 20 37 95 68 87 39 31 5 100 9 23 74 80 7 27 50 69 52 82 81 85 56 84 34 32 17 36 11 16 8 57 49 30 60 86 62 99 13 19 98 43 6 4 46 58 64 45 51 53 10 28 90 26 40 94 35 22 61 15 47 1 55 ...

output:

1
4
2
3
2
4
0
2
1
1
1
0
0
4
0
4
3
2
2
1
4
0
4
0
2
2
4
2
2
0
2
2
1
0
0
1
3
2
2
0
0
0
3
2
0
1
4
1
2
2
3
1
3
0
2
1
1
4
2
1
0
0
3
0
0
2
0
2
4
3
0
4
0
0
3
0
2
2
0
4
3
4
2
3
2
0
2
0
1
1
2
1
2
1
4
0
1
0
1
2
0
2
4
1
0
2
4
2
3
1
4
2
0
2
0
2
0
2
2
0
1
2
1
2
0
3
2
1
2
1
1
4
1
1
1
2
1
2
2
1
0
2
0
1
0
1
1
1
0
2
...

result:

ok 200000 lines

Test #9:

score: 0
Accepted
time: 886ms
memory: 17156kb

input:

1
316 632 200000
36 93 100 184 246 134 89 157 219 9 18 29 8 109 159 3 255 66 257 27 290 286 283 132 216 175 167 208 238 31 220 296 271 113 269 127 156 300 121 267 99 122 90 288 64 210 28 144 262 60 53 6 96 268 276 279 13 174 287 78 295 72 143 155 146 197 107 35 24 88 187 110 163 204 2 25 226 119 164...

output:

7
87
10
47
74
55
79
64
19
2
104
21
54
1
4
72
81
57
12
74
28
77
82
77
7
22
56
6
81
4
28
24
56
19
25
7
7
4
64
68
51
16
95
23
67
31
33
45
72
69
65
7
24
11
85
25
0
1
0
20
72
43
56
12
16
76
98
91
50
84
23
71
8
14
22
49
64
3
24
2
15
5
90
11
26
40
3
12
4
23
88
65
34
42
25
4
80
3
6
20
41
83
12
10
43
24
3
77...

result:

ok 200000 lines

Test #10:

score: 0
Accepted
time: 1660ms
memory: 15184kb

input:

1
632 316 200000
625 142 323 331 85 521 376 51 411 31 418 11 16 66 112 611 459 622 148 247 122 587 249 141 20 88 439 334 233 474 305 381 203 559 228 595 326 535 128 449 138 28 86 56 109 102 428 194 612 256 466 598 189 539 237 59 225 528 200 330 490 560 133 57 590 632 422 213 340 310 49 195 41 217 19...

output:

60
34
45
304
31
71
52
36
123
38
76
28
200
223
55
58
11
275
202
76
285
30
154
113
40
48
355
332
358
33
240
46
29
91
147
75
318
62
162
200
171
124
228
31
285
59
16
206
114
44
163
87
53
65
221
298
23
172
123
91
298
14
57
6
8
71
1
84
3
2
58
20
6
111
244
220
25
137
86
269
134
254
68
64
129
14
65
108
43
3...

result:

ok 200000 lines

Test #11:

score: 0
Accepted
time: 499ms
memory: 11292kb

input:

1
447 447 200000
108 218 332 238 439 329 405 417 75 380 227 395 285 112 24 290 141 390 269 155 364 36 79 403 170 284 348 250 93 331 232 90 419 228 21 424 213 365 353 404 274 144 146 291 88 29 44 12 362 233 312 369 400 95 142 17 327 111 414 86 58 314 163 401 358 197 441 157 160 40 220 180 283 10 63 6...

output:

720
254
101
688
77
209
15
516
644
262
61
102
719
85
49
52
471
94
275
145
3
714
101
385
407
241
154
441
839
247
124
278
100
290
408
290
567
42
72
320
296
528
471
420
293
295
688
516
354
159
812
468
487
671
190
514
396
154
887
64
119
125
604
27
901
669
651
148
432
673
291
183
3
123
946
722
783
382
367...

result:

ok 200000 lines

Test #12:

score: -100
Time Limit Exceeded

input:

2
10000 10 100000
9169 6526 4977 9620 6327 8688 1778 4867 8252 2611 762 6164 1606 5796 6803 7006 5759 9972 8099 6268 5700 9868 896 2146 7128 1326 2696 2311 8764 6495 8013 6340 8057 6116 8447 5480 6736 9968 1048 1357 9013 8647 2334 8332 1514 6336 1486 5441 2963 2814 6910 4862 9616 1340 9839 3105 3703...

output:

43
225
406
1980
718
2299
362
985
1715
111
2449
1855
241
1928
461
1018
2304
1158
2562
446
176
1874
1743
8
165
1024
1025
2514
267
2165
1126
428
1804
14
969
590
765
1839
293
2166
1189
434
83
1862
916
48
2000
126
1170
101
2535
809
1422
589
123
44
1265
794
1025
1568
88
1483
498
2464
904
511
997
305
513
2...

result: