QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#763010#9731. Fuzzy RankingSSAABBEERRWA 15ms24228kbC++203.4kb2024-11-19 17:43:152024-11-19 17:43:20

Judging History

This is the latest submission verdict.

  • [2024-11-25 12:28:53]
  • hack成功,自动添加数据
  • (/hack/1257)
  • [2024-11-19 17:43:20]
  • Judged
  • Verdict: WA
  • Time: 15ms
  • Memory: 24228kb
  • [2024-11-19 17:43:15]
  • Submitted

answer

#include<bits/stdc++.h>
#define endl '\n'
#define int long long
#define rep(i, a, b) for(int i = a; i <= b; i ++ )
#define pre(i, a, b) for(int i = a; i >= b; i -- )
using namespace std;
const int N = 1e6 + 10;
int n, m, k, q;
int stk[N], instk[N], top, cnt, id[N], dfn[N], low[N], times, sz[N], idx;
vector<int>p[N], pp[N], ppp[N], res[N];
void tarjan(int u)
{
    dfn[u] = low[u] = ++times;
    stk[++top] = u, instk[u] = 1;
    for(auto j : p[u])
    {
        if(!dfn[j]) tarjan(j), low[u] = min(low[u], low[j]);
        else if(instk[j]) low[u] = min(low[u], dfn[j]);
    }
    if(dfn[u] == low[u])
    {
        cnt ++ ;
        int y;
        do
        {
            y = stk[top -- ];
            id[y] = cnt;
            sz[cnt] ++ ;
            instk[y] = 0;
        }while(y != u);
    }
}
int f[N], num[N], in[N], sum[N], w[N];
void solve()
{
    idx = 0;
    cin >> n >> k >> q;
    rep(i, 1, n) p[i].clear(), id[i] = 0, sz[i] = 0, in[i] = 0, f[i] = 0, ppp[i].clear(), res[i].clear(), sum[i] = 0, w[i] = 0, num[i] = 0, pp[i].clear(), stk[i] = 0, instk[i] = 0, dfn[i] = 0, low[i] = 0;
    times = 0, cnt = 0, top = 0;
    rep(i, 1, k)
    {
        int last = 0;
        rep(j, 1, n)
        {
            int x;
            cin >> x;
            pp[i].push_back(x);
            if(last) p[last].push_back(x);
            last = x;
        }
    }
    rep(i, 1, n) if(!dfn[i]) tarjan(i);
    rep(i, 1, n) ppp[id[i]].push_back(i);
    rep(i, 1, n)
    {
        for(auto j : p[i])
        {
            if(id[i] != id[j])
            {
                f[id[j]] = id[i], in[id[i]] ++ ;
            }
        }
    }
    rep(i, 1, cnt)
    {
        if(!in[i])
        {
            while(i)
            {
                num[++idx] = i;
                i = f[i];
            }
            break;
        }
    }
    rep(i, 1, idx / 2) swap(num[i], num[idx - i + 1]);
    rep(i, 1, idx)
    {
        // cout<<num[i];
        sum[i] = sum[i - 1] + (sz[num[i]] * (sz[num[i]] - 1)) / 2;
        for(auto it : ppp[num[i]])
        {
            w[it] = i;
        }
    }
    rep(i, 1, k)
    {
        for(auto it : pp[i])
        {
            res[i].push_back(w[it]);
        }
    }
    int last = 0, op, l, r;
    // for(auto it : res[1])cout<<it<<" ";
    // cout<<cnt;
    while(q -- )
    {
        cin >> op >> l >> r;
        op = (op + last) % k + 1;
        l = (l + last) % n + 1;
        r = (r + last) % n + 1;
        // cout<<op<<" "<<l<<" "<<r<<endl;
        if(id[l] == id[r])
        {
            int z = r - l + 1;
            cout << (z * (z - 1)) / 2 << endl;
            last = (z * (z - 1)) / 2;
        }
        else
        {
            int ans = 0;
            int tl = upper_bound(res[op].begin(), res[op].end(), w[pp[op][l - 1]]) - res[op].begin() + 1;
            tl -- ;
            // cout<<tl;
            ans += (tl - l + 1) * (tl - l) / 2;
            int tr = lower_bound(res[op].begin(), res[op].end(), w[pp[op][r - 1]]) - res[op].begin() + 1;
            ans += (r - tr + 1) * (r - tr) / 2;
            if(id[r] - id[l] > 1) ans += sum[id[r] - 1] - sum[id[l]];
            cout << ans << endl;
            last = ans;
        }
    }
}
signed main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
    int _;
    _ = 1;
    cin >> _;
    while(_ -- )
    {
        solve();
    }
    return 0;
}

詳細信息

Test #1:

score: 100
Accepted
time: 3ms
memory: 24176kb

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: 15ms
memory: 24228kb

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:

0
0
2
0
1
2
0
2
3
0
4
0
0
0
6
0
0
3
0
0
1
6
28
0
0
10
10
6
6
15
0
3
15
15
18
3
1
1
6
13
1
15
2
1
6
5
3
3
1
12
1
0
3
0
0
3
4
1
0
0
0
0
1
1
1
0
0
1
1
0
1
0
0
3
0
1
0
0
3
3
3
6
16
16
0
11
16
1
4
21
2
2
4
1
2
1
1
1
1
1
0
0
0
0
0
0
0
0
0
0
1
0
0
28
3
0
9
1
0
0
0
0
0
0
0
0
0
0
0
0
0
4
0
1
0
0
0
0
0
6
9
4
...

result:

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