QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#745600 | #9731. Fuzzy Ranking | atuer | WA | 33ms | 20096kb | C++23 | 3.0kb | 2024-11-14 10:45:44 | 2024-11-14 10:45:45 |
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];
set<int> edge[maxn];
unordered_map<int, int> mp;
int idx = 0;
int b[maxn], vis[maxn];
void dfs(int x)
{
// cout << " -> " << x << endl;
b[x] = x, vis[x] = 1;
for (int y : edge[x])
{
// cout << "?" << y << endl;
if (!vis[y])
dfs(y);
b[x] = min(b[x], b[y]);
}
}
void solve()
{
cin >> n >> m >> q;
mp.clear(), idx = 0;
for (int i = 1; i <= n; i++)
edge[i].clear(), vis[i] = 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]);
if (i > 1)
{
// cout << a[j][i - 1] << " ->>> " << a[j][i] << endl;
edge[a[j][i - 1]].insert(a[j][i]);
}
}
}
// for (int j = 1; j <= m; j++)
// {
// for (int i = 1; i <= n; i++)
// cout << a[j][i] << " ";
// cout << endl;
// }
dfs(1);
// for (int j = 1; j <= m; j++)
// for (int i = 2; i <= n; i++)
// b[a[j][i - 1]] = min(b[a[j][i - 1]], a[j][i]);
// for (int i = n; i >= 1; i--)
// b[i] = min(b[i + 1], b[i]);
// 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;
// cout << "{ " << x << " " << l << " " << r << endl;
auto ll = qj.lower_bound(l);
auto rr = -- --qj.upper_bound(r + 1);
// cout << "[ " << ll->first << " " << rr->first << " " << endl;
// cout << ll << "~" << rr << endl;
int res = 0;
if ((--ll)->first <= rr->first)
{
res += rr->second - ll->second;
int qr = (++ll)->first - 1, ql = (++rr)->first;
res += val[max(qr - l + 1, 0ll)];
res += val[max(r - ql + 1, 0ll)];
}
else
{
int ql = l, qr = r;
while (ql < qr)
{
int mid = (ql + qr + 1) / 2;
if (b[l] == b[mid])
ql = mid;
else
qr = mid - 1;
}
res += val[max(ql - l + 1, 0ll)];
res += val[max(r - (ql + 1) + 1, 0ll)];
// res += val[max(r - l + 1, 0ll)];
}
// cout << qj[rr] - qj[ll1] << endl;
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: 0ms
memory: 19392kb
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: 16ms
memory: 17728kb
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 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0 6 6 1 1 1 0 1 1 0 0 1 0 0 0 3 0 1 1 0 2 3 3...
result:
wrong answer 924th lines differ - expected: '10', found: '6'