QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#763064 | #9731. Fuzzy Ranking | SSAABBEERR | WA | 536ms | 792028kb | C++20 | 3.9kb | 2024-11-19 18:02:35 | 2024-11-19 18:02:41 |
Judging History
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 = 2e5 + 10;
int n, m, k, q;
int stk[N], instk[N], top, cnt, id[N], dfn[N], low[N], times, sz[N], idx, dd[N];
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, dd[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)
{
dd[num[i]] = i;
// 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[4])cout<<it<<" ";
// cout<<cnt;
// cout<<id[3]<<" "<<id[6];
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[pp[op][l - 1]] == id[pp[op][r - 1]])
{
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 -- ;
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;
// cout<<w[pp[op][l - 1]];
if(w[pp[op][r - 1]] - w[pp[op][l - 1]] > 1)
{
// cout<<w[pp[op][r - 1]] - 1;
ans += (sum[w[pp[op][r - 1]] - 1] - sum[w[pp[op][l - 1]]]);
}
cout << ans << endl;
last = ans;
}
}
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, dd[i] = 0;
}
int 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: 2ms
memory: 9832kb
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: 10ms
memory: 11828kb
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 1 6 28 0 0 10 10 6 6 15 0 3 10 6 16 6 11 1 2 1 1 6 3 3 0 4 5 3 4 1 1 3 2 4 0 3 4 4 4 4 0 0 1 1 2 0 0 1 2 1 1 0 0 1 4 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 3 3 9 1 9 4 ...
result:
ok 20000 lines
Test #3:
score: 0
Accepted
time: 23ms
memory: 11832kb
input:
8000 5 5 10 3 5 2 4 1 3 2 5 4 1 3 5 2 4 1 3 5 2 4 1 3 5 2 4 1 1 1 1 4 1 3 1 0 3 4 2 3 1 0 1 3 2 3 1 2 3 3 0 2 1 1 3 1 1 2 5 5 10 5 3 1 2 4 3 5 1 2 4 5 3 1 2 4 3 5 1 2 4 5 3 1 2 4 0 0 1 2 0 1 4 1 2 1 3 4 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 3 0 0 0 3 1 0 10 0 4 0 0 2...
result:
ok 40000 lines
Test #5:
score: 0
Accepted
time: 536ms
memory: 792028kb
input:
2000 1 100 100 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 25 0 0 9 0 0 80 0 0 37 0 0 18 0 0 24 0 0 5 0 0 87 0 0 50 0 0 63 0 0 53 0 0 62 0 0 37 ...
output:
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 ...
result:
ok 200000 lines
Test #6:
score: -100
Wrong Answer
time: 23ms
memory: 20688kb
input:
10 20 1000 2000 2 5 1 3 12 16 14 15 7 4 19 13 18 10 20 9 11 8 6 17 5 2 12 1 16 3 19 4 7 15 14 18 13 10 9 20 11 8 6 17 2 5 1 16 12 3 7 14 4 19 15 13 18 10 20 9 11 17 6 8 2 5 1 16 3 12 15 7 4 14 19 18 13 10 9 20 11 8 6 17 5 2 3 12 1 16 14 7 4 15 19 18 13 10 20 9 11 6 17 8 2 5 3 1 12 16 19 15 7 4 14 18...
output:
11 0 11 10 1 11 5 10 10 5 13 2 0 18 2 14 2 18 10 13 1 1 0 1 4 7 6 0 15 11 1 4 6 19 3 9 3 1 0 20 2 16 1 0 3 2 3 0 18 1 17 1 1 8 1 5 17 1 3 6 1 2 15 15 2 1 0 3 18 22 0 1 2 15 13 12 20 3 0 9 15 1 4 17 22 16 8 6 13 0 7 11 15 19 15 6 7 10 17 12 9 1 11 1 0 4 6 17 1 17 6 5 1 1 16 14 3 1 12 18 1 0 18 12 17 ...
result:
wrong answer 2001st lines differ - expected: '4', found: '1056'