QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#864115#9731. Fuzzy RankingthangdzwinioiWA 12ms3712kbC++201.9kb2025-01-20 10:34:292025-01-20 10:34:31

Judging History

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

  • [2025-01-20 10:34:31]
  • 评测
  • 测评结果:WA
  • 用时:12ms
  • 内存:3712kb
  • [2025-01-20 10:34:29]
  • 提交

answer

#include <bits/stdc++.h>

using namespace std;
using ll = long long;

template <int D, typename T>
struct Vec : public vector<Vec<D - 1, T>> {
    static_assert(D >= 1, "Dimension must be positive");
    template <typename... Args>
    Vec(int n = 0, Args... args) : vector<Vec<D - 1, T>>(n, Vec<D - 1, T>(args...)) {}
};

template <typename T>
struct Vec<1, T> : public vector<T> {
    Vec(int n = 0, T val = T()) : std::vector<T>(n, val) {}
};

ll zs(int len){
    return ll(len - 1) * len / 2;
}

void process(){
    int n, k, q; cin >> n >> k >> q;
    Vec <2, int> a(k, n);
    for (int i = 0; i < k; ++ i){
        for (int j = 0; j < n; ++ j) {
            cin >> a[i][j];
            a[i][j] --;
        }
    }

    vector <int> cnt(n, 0), used(n, 0);
    int nap = 0, nca = 0;
    vector <int> dv = {-1};
    for (int j = 0; j < n; ++ j){
        for (int i = 0; i < k; ++ i){
            int v = a[i][j];
            nap += (!used[v]);
            used[v] = 1;
            cnt[v] ++;
            nca += (cnt[v] == k);
        }

        if (nap == nca) dv.push_back(j);
    }

    int nbl = dv.size();
    vector <long long> pref(nbl, 0);
    for (int i = 1; i < nbl; ++ i){
        int len = dv[i] - dv[i - 1];
        pref[i] = pref[i - 1] + zs(len);
    }

    ll lastans = 0;
    while (q --){
        int id, l, r;
        cin >> id >> l >> r;
        l = (lastans + l) % n;
        r = (lastans + r) % n;

        int v = upper_bound(dv.begin(), dv.end(), r) - dv.begin() - 1;
        int u = lower_bound(dv.begin(), dv.end(), l) - dv.begin();

        lastans = pref[v] - pref[u];
        lastans += zs(r - dv[v]) + zs(dv[u] - l + 1);

        cout << lastans << "\n";
    }
}

int main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);

    int t; cin >> t; while (t --)
    process();

    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

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: 12ms
memory: 3712kb

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
-14
46
28
-20
114
10
6
6
1
-39
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
0
0
-3
0
4
4
1
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
0
...

result:

wrong answer 21st lines differ - expected: '1', found: '-14'