QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#743064#9731. Fuzzy RankingKJJDWA 17ms3840kbC++203.4kb2024-11-13 18:08:082024-11-13 18:08:12

Judging History

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

  • [2024-11-25 12:28:53]
  • hack成功,自动添加数据
  • (/hack/1257)
  • [2024-11-13 18:08:12]
  • 评测
  • 测评结果:WA
  • 用时:17ms
  • 内存:3840kb
  • [2024-11-13 18:08:08]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;
const int INF = 1e9;
void solve()
{
    int n, k, q;
    cin >> n >> k >> q;
    vector rk(k, vector<int>(n)), g(n, vector<int>());
    for (int i = 0; i < k; i++)
        for (int j = 0; j < n; j++)
        {
            cin >> rk[i][j];
            rk[i][j]--;
        }
    vector<int> scc(n), vis(n), stk, dfn(n), low(n);
    int tot = 0, scccnt = 0;
    auto tarjan = [&](auto self, int u) -> void {
        dfn[u] = low[u] = ++tot;
        stk.push_back(u);
        vis[u] = 1;
        for (auto v : g[u])
        {
            if (!dfn[v])
            {
                self(self, v);
                low[u] = min(low[u], low[v]);
            }
            else if (vis[v])
            {
                low[u] = min(low[u], dfn[v]);
            }
        }
        if (low[u] == dfn[u])
        {
            int v;
            ++scccnt;
            do
            {
                v = stk.back();
                stk.pop_back();
                vis[v] = 0;
                scc[v] = scccnt;
            } while (v != u);
        }
    };
    for (int i = 0; i < k; i++)
        for (int j = 1; j < n; j++)
            g[rk[i][j]].push_back(rk[i][j - 1]);
    for (int i = 0; i < n; i++)
        if (!dfn[i])
            tarjan(tarjan, i);
    vector Ls(k, vector<pair<int, int>>());
    for (int j = 0; j < k; j++)
    {
        int pre = scc[rk[j][0]];
        // Ls[j].push_back(0);
        int l = 0;
        for (int i = 1; i < n; i++)
        {
            if (pre != scc[rk[j][i]])
            {
                // pref[j].push_back(( i - Ls[j].back() ) * (i - Ls[j].back() - 1) / 2);
                Ls[j].push_back({l, i});
                pre = scc[rk[j][i]];
                l = i;
            }
        }
        if (l != n - 1)
            Ls[j].push_back({l, n});
        Ls[j].push_back({n, n});
    }
    const int M = Ls[0].size();
    vector pref(k, vector<int64_t>(M));
    for (int j = 0; j < k; j++)
    {
        for (int i = 1; i < M; i++)
        {
            int64_t len = Ls[j][i].first - Ls[j][i - 1].first;
            pref[j][i] = pref[j][i - 1] + (len) * (len - 1) / 2;
        }
    }
    int64_t pre = 0;
    while (q--)
    {
        int l, r, id;
        cin >> id >> l >> r;
        id = (id + pre) % k;
        tie(l, r) = minmax((l + pre) % n, (r + pre) % n);
        // cout << l << ' ' << r << '\n';
        auto L = upper_bound(Ls[id].begin(), Ls[id].end(), make_pair(l, INF)) - Ls[id].begin();
        auto R = upper_bound(Ls[id].begin(), Ls[id].end(), make_pair(r, INF)) - Ls[id].begin();
        if (L == R)
        {
            int64_t len = (r - l + 1);
            cout << (len) * (len - 1) / 2 << '\n';
            pre = (len) * (len - 1) / 2;
            continue;
        }
        int64_t res = pref[id][R - 1] - pref[id][L];
        int64_t lcnt = 0, rcnt = 0;
        lcnt = Ls[id][L].first - l;
        rcnt = r - Ls[id][R - 1].first + 1;
        res += lcnt * (lcnt - 1) / 2;
        res += rcnt * (rcnt - 1) / 2;
        cout << res << '\n';
        pre = res;
    }
}

int main()
{
#ifdef LOCAL
    freopen("data.in", "r", stdin);
    freopen("data.out", "w", stdout);
#endif
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int T;
    cin >> T;
    while (T--)
        solve();
    return 0;
}

详细

Test #1:

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

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: 17ms
memory: 3584kb

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
5
0
0
1
6
28
0
0
10
10
6
6
15
0
3
10
6
22
3
10
24
6
1
1
6
3
3
0
4
5
3
4
1
1
4
3
4
0
3
4
5
3
1
0
0
3
1
4
0
0
1
4
1
1
0
0
1
5
3
0
5
0
2
3
6
16
16
0
11
16
1
4
15
1
4
2
1
1
2
1
2
2
4
0
0
0
1
0
0
0
0
0
0
1
1
0
6
3
0
3
5
0
0
0
1
1
0
0
0
0
0
1
0
6
1
0
1
6
0
0
0
6
0
9
1
9
4...

result:

wrong answer 18th lines differ - expected: '4', found: '5'