QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#745332 | #9731. Fuzzy Ranking | atuer | WA | 14ms | 8996kb | C++23 | 2.2kb | 2024-11-14 09:14:17 | 2024-11-14 09:14:17 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define double long double
#define endl "\n"
const int maxn = 2e5 + 7, oo = 1e18 + 7;
int val[maxn];
int n, m, q;
vector<int> a[maxn];
unordered_map<int, int> mp;
int idx = 0;
int b[maxn];
void solve()
{
cin >> n >> m >> q;
mp.clear(), idx = 0;
for (int j = 1; j <= m; j++)
{
a[j].clear(), a[j].push_back(-1);
for (int i = 1; i <= n; i++)
{
int x;
cin >> x;
if (!mp[x])
mp[x] = ++idx;
a[j].push_back(mp[x]);
}
}
// for (int j = 1; j <= m; j++)
// {
// for (int i = 1; i <= n; i++)
// cout << a[j][i] << " ";
// cout << endl;
// }
for (int i = 1; i <= n; i++)
b[i] = i;
for (int j = 1; j <= m; j++)
for (int i = 1; i <= n; i++)
b[i] = min(b[i], a[j][i]);
for (int i = n - 1; i >= 1; i--)
b[i] = min(b[i + 1], b[i]);
b[n + 1] = oo;
// for (int i = 1; i <= n; i++)
// cout << b[i] << " ";
// cout << endl;
map<int, int> qj;
qj[0] = 0;
int now = 1;
while (now <= n)
{
int j = now;
while (j < n && b[j + 1] == b[now])
j++;
qj[now] = qj.rbegin()->second + val[j - now + 1];
now = j + 1;
}
qj[n + 1] = qj.rbegin()->second;
// for (auto i : qj)
// {
// cout << i.first << " " << i.second << endl;
// }
int ans = 0;
while (q--)
{
int x, l, r;
cin >> x >> l >> r;
x = ((x + ans) % m) + 1;
l = ((l + ans) % n) + 1;
r = ((r + ans) % n) + 1;
int ll = qj.lower_bound(l)->first;
int ll1 = (--qj.lower_bound(l))->first;
auto rr = qj.upper_bound(r);
if (r + 1 == rr->first)
rr--;
else
rr--, rr--;
// cout << ll << "~" << rr << endl;
int res = rr->second - qj[ll1];
// cout << qj[rr] - qj[ll1] << endl;
int qr = ll - 1, ql = (++rr)->first;
res += val[max(qr - l + 1, 0ll)];
res += val[max(r - ql + 1, 0ll)];
cout << res << endl;
ans = res;
}
}
signed main()
{
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
cout << fixed << setprecision(10);
val[0] = 0;
for (int i = 1; i < maxn; i++)
val[i] = val[i - 1] + i - 1;
int t = 1;
cin >> t;
while (t--)
solve();
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 1ms
memory: 8996kb
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
Wrong Answer
time: 14ms
memory: 5676kb
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 -11 36 46 0 -34 37 36 0 36 -30 0 3 10 6 16 5 9 0 3 1 1 6 3 3 0 4 5 3 4 1 1 3 2 4 -1 2 -2 0 -3 -1 0 0 1 1 2 0 0 1 2 1 1 0 -1 -4 -2 -4 -1 0 0 2 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...
result:
wrong answer 21st lines differ - expected: '1', found: '-11'