QOJ.ac
QOJ
The 2nd Universal Cup Finals is coming! Check out our event page, schedule, and competition rules!
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#853476 | #9731. Fuzzy Ranking | thinking (Fedor Romashov, Alexey Mikhnenko, Gimran Abdullin)# | RE | 0ms | 3616kb | C++20 | 2.0kb | 2025-01-11 17:07:17 | 2025-01-11 17:07:23 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
#define all(a) begin(a), end(a)
#define len(a) int((a).size())
#ifdef LOCAL
#include "debug.h"
#else
#define dbg(...)
#define dprint(...)
#define debug if constexpr (false)
#endif // LOCAL
void solve(int /* test_num */) {
int n, k, q;
cin >> n >> k >> q;
vector<vector<int>> p(k, vector<int>(n));
for (auto &v : p) {
for (auto &x : v) {
cin >> x;
x--;
}
}
vector<int> cuts;
int mx = 0;
for (int i = 0; i < n; i++) {
for (int j = 0; j < k; j++) {
mx = max(mx, p[j][i]);
}
if (mx == i) {
cuts.push_back(i);
}
}
vector<int> comp(n), nxt(n), prev(n);
for (int i = len(cuts) - 1; i >= 0; i--) {
int p = (i == 0 ? -1 : cuts[i - 1]);
for (int j = cuts[i]; j > p; j--) {
comp[j] = cuts[i] - p;
nxt[j] = cuts[i];
prev[j] = p + 1;
}
}
vector<ll> pref(n + 1);
for (int i = 0; i < n; i++) {
pref[i + 1] = pref[i] + comp[i];
}
ll ans = 0;
while (q--) {
int id, l, r;
cin >> id >> l >> r;
id = (id + ans) % k;
l = (l + ans) % n;
r = (r + ans) % n;
r++;
assert(l < r);
ans = pref[r] - pref[l];
ans -= r - l;
{
int pos = min(r - 1, nxt[l]);
ans -= 1ll * (l - prev[l]) * (pos - l + 1);
}
{
int pos = prev[r - 1];
ans -= 1ll * (nxt[r - 1] - r + 1) * (r - pos);
}
assert(ans % 2 == 0);
ans /= 2;
cout << ans << '\n';
}
}
int main() {
cin.tie(nullptr)->sync_with_stdio(false);
int tests;
cin >> tests;
for (int test_num = 1; test_num <= tests; test_num++) {
solve(test_num);
}
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3616kb
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: -100
Runtime Error
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 ...