QOJ.ac
QOJ
ID | Submission ID | Problem | Hacker | Owner | Result | Submit time | Judge time |
---|---|---|---|---|---|---|---|
#1257 | #780598 | #9731. Fuzzy Ranking | RWeakest | RWeakest | Success! | 2024-11-25 12:28:28 | 2024-11-25 12:28:30 |
Details
Extra Test:
Time Limit Exceeded
input:
1 100000 2 200000 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 ...
output:
4999850001 4999850001 4999850001 4999850001 4999850001 4999850001 4999850001 4999850001 4999850001 4999850001 4999850001 4999850001 4999850001 4999850001 4999850001 4999850001 4999850001 4999850001 4999850001 4999850001 4999850001 4999850001 4999850001 4999850001 4999850001 4999850001 4999850001 499...
result:
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#780598 | #9731. Fuzzy Ranking | RWeakest | TL | 47ms | 18120kb | C++20 | 1.8kb | 2024-11-25 11:46:04 | 2024-11-25 12:32:56 |
answer
#include <bits/stdc++.h>
using namespace std;
#define ll long long
const int N = 2e5 + 100;
ll T, n, k, q;
ll ans[N], cnt[N], r[N];
ll id, li, ri, v;
vector<int> a[N];
void solve() {
cin >> n >> k >> q;
for (int i = 0; i <= n; i++) ans[i] = 0, cnt[i] = 0, r[i] = 0;
for (int i = 0; i <= k; i++) a[i].clear();
for (int i = 1; i <= k; i++) {
a[i].push_back(-1);
int temp;
for (int j = 1; j <= n; j++) {
cin >> temp;
a[i].push_back(temp);
}
}
int full = 0;
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= k; j++) {
cnt[a[j][i]]++;
if (cnt[a[j][i]] == k) full++;
}
if (full == i) r[i] = i;
}
ll p = r[n];
for (int i = n - 1; i >= 1; i--) {
if (r[i]) p = r[i];
else r[i] = p;
}
ll add = 0;
for (int i = 1; i <= n; i++) {
ans[i] = ans[i - 1] + add;
if (r[i] != i) add++;
else add = 0;
}
//for (int i = 1; i <= n; i++) printf("%d: r:%lld ans:%lld\n", i, r[i], ans[i]);
v = 0;
while (q--) {
cin >> id >> li >> ri;
id = (id + v) % k + 1, li = (li + v) % n + 1, ri = (ri + v) % n + 1;
// printf("id %lld li %lld ri %lld\n", id, li, ri);
if (r[li] < ri) v = ans[ri] - ans[r[li]];
else v = 0;
add = 0;
for (int i = li; i <= min(r[li], ri); i++) {
v += add;
add++;
}
cout << v << "\n";
}
}
int main() {
std::ios::sync_with_stdio(false);
std::cin.tie(nullptr), std::cout.tie(nullptr);
cin >> T;
while (T--) {
solve();
}
return 0;
}
/*
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
*/