QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#865581 | #9731. Fuzzy Ranking | Purslane# | RE | 51ms | 73696kb | C++14 | 2.2kb | 2025-01-21 20:03:23 | 2025-01-21 20:03:25 |
Judging History
answer
#include<bits/stdc++.h>
#define ll long long
#define ffor(i,a,b) for(int i=(a);i<=(b);i++)
#define roff(i,a,b) for(int i=(a);i>=(b);i--)
using namespace std;
const int MAXN=2e5+10,MAXM=310;
int T,n,k,q,t,bl,in[MAXN],low[MAXN],dfn[MAXN],col[MAXN],cls,bel[MAXN],L[MAXM],R[MAXM],cnt[MAXN],c[MAXN];
vector<int> p[MAXN],G[MAXN];
stack<int> st;
void tarjan(int u) {
st.push(u),dfn[u]=low[u]=++t,in[u]=1;
for(auto v:G[u]) {
if(!dfn[v]) tarjan(v),low[u]=min(low[u],low[v]);
else if(in[v]) low[u]=min(low[u],dfn[v]);
}
if(dfn[u]==low[u]) {
++cls;
while(1) {
int v=st.top();
st.pop(),col[v]=cls,in[v]=0;
if(u==v) break ;
}
}
return ;
}
ll sum[MAXM][MAXM];
int pre[MAXM][MAXN];
ll query(int l,int r) {
if(bel[l]==bel[r]) {
ll ans=0;
ffor(j,l,r) ans+=cnt[c[j]],cnt[c[j]]++;
ffor(j,l,r) cnt[c[j]]=0;
return ans;
}
ll ans=sum[bel[l]+1][bel[r]-1];
ffor(j,L[bel[r]],r) ans+=pre[bel[r]-1][c[j]]-pre[bel[l]][c[j]]+cnt[c[j]],cnt[c[j]]++;
ffor(j,l,R[bel[l]]) ans+=pre[bel[r]-1][c[j]]-pre[bel[l]][c[j]]+cnt[c[j]],cnt[c[j]]++;
ffor(j,L[bel[r]],r) cnt[c[j]]=0;
ffor(j,l,R[bel[l]]) cnt[c[j]]=0;
return ans;
}
int main() {
ios::sync_with_stdio(false),cin.tie(0),cout.tie(0);
cin>>T;
while(T--) {
cin>>n>>k>>q;
ffor(i,1,k) p[i].clear();
ffor(i,1,n) G[i].clear();
ffor(i,1,k) {
int lst=0,id;
p[i].push_back(0);
ffor(j,1,n) {
cin>>id;
if(lst) G[lst].push_back(id);
lst=id,p[i].push_back(id);
}
}
cls=0,t=0;
ffor(i,1,n) in[i]=dfn[i]=low[i]=col[i]=0;
ffor(i,1,n) if(!dfn[i]) tarjan(i);
bl=(n*k+299)/300;
ffor(i,1,bl) L[i]=(i-1)*300+1,R[i]=i*300;
R[bl]=n*k;
ffor(i,1,k) ffor(j,1,n) c[(i-1)*n+j]=col[p[i][j]];
ffor(i,1,bl) ffor(j,L[i],R[i]) bel[j]=i;
ffor(i,1,bl) {
ll ans=0;
ffor(j,i,bl) {
ffor(t,L[j],R[j]) ans+=cnt[c[t]],cnt[c[t]]++;
sum[i][j]=ans;
}
ffor(k,1,cls) pre[i][k]=pre[i-1][k];
ffor(j,L[i],R[i]) pre[i][c[j]]++;
ffor(k,1,cls) cnt[k]=0;
}
ll ans=0;
ffor(i,1,q) {
ll id,l,r;
cin>>id>>l>>r;
id=(id+ans)%k+1;
l=(l+ans)%n+1;
r=(r+ans)%n+1;
cout<<(ans=query((id-1)*n+l,(id-1)*n+r))<<'\n';
}
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 18148kb
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: 12ms
memory: 18152kb
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 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 1 0 2 3 3...
result:
ok 80000 lines
Test #4:
score: 0
Accepted
time: 15ms
memory: 20200kb
input:
8000 5 5 5 1 3 5 2 4 5 3 2 1 4 5 2 1 3 4 3 1 2 5 4 1 3 2 5 4 1 1 2 1 4 0 1 4 1 2 2 2 4 1 3 5 5 5 2 3 4 1 5 2 3 4 1 5 2 3 4 5 1 2 3 4 1 5 2 3 4 5 1 2 0 4 0 0 0 4 1 3 3 0 1 4 4 4 5 5 5 2 5 4 1 3 2 5 4 1 3 2 5 4 1 3 2 5 4 1 3 2 5 4 1 3 3 1 3 2 0 4 0 1 3 4 0 2 3 4 4 5 5 5 1 2 4 5 3 1 2 4 5 3 1 2 4 5 3 1...
output:
1 1 3 0 3 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 1 1 1 3 0 1 0 0 0 1 0 0 1 1 1 1 3 0 3 0 0 0 0 0 10 3 1 3 1 2 1 1 1 0 3 3 1 0 1 6 3 6 6 1 0 0 0 0 0 0 2 1 2 0 3 1 1 1 3 1 3 1 3 3 6 3 6 0 1 1 0 6 0 3 1 1 1 1 0 0 0 0 0 0 6 0 0 10 1 0 0 0 1 2 1 1 0 0 0 1 1 1 0 0 1 0 1 1 0 1 3 0 0 0 3 1 0 10 0 4 0 0 2...
result:
ok 40000 lines
Test #5:
score: 0
Accepted
time: 35ms
memory: 20208kb
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: 0
Accepted
time: 16ms
memory: 73696kb
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:
ok 20000 lines
Test #7:
score: 0
Accepted
time: 21ms
memory: 34496kb
input:
33 3 2000 2000 1 2 3 2 1 3 2 1 3 2 1 3 1 2 3 2 1 3 2 1 3 1 2 3 2 1 3 1 2 3 2 1 3 2 1 3 2 1 3 1 2 3 2 1 3 2 1 3 2 1 3 1 2 3 2 1 3 2 1 3 1 2 3 1 2 3 2 1 3 1 2 3 2 1 3 1 2 3 2 1 3 1 2 3 2 1 3 2 1 3 1 2 3 2 1 3 2 1 3 2 1 3 1 2 3 2 1 3 1 2 3 1 2 3 2 1 3 1 2 3 1 2 3 1 2 3 1 2 3 2 1 3 2 1 3 1 2 3 2 1 3 2 1...
output:
1 1 0 1 0 0 1 0 0 0 0 0 0 1 1 0 0 0 1 1 0 0 0 0 1 0 1 0 0 0 0 1 0 0 1 0 1 0 0 0 1 0 1 0 0 0 0 1 0 0 1 1 0 1 0 0 1 0 1 1 0 0 0 1 1 0 1 1 0 1 0 1 0 0 0 1 0 0 0 1 1 1 1 0 0 0 1 0 1 0 0 0 0 1 1 0 0 1 1 1 0 1 1 0 0 1 0 0 0 0 1 0 0 0 0 0 0 0 1 1 1 0 0 0 0 1 0 1 0 1 0 0 0 1 1 1 0 0 0 0 0 0 0 0 0 0 1 1 0 0 ...
result:
ok 66000 lines
Test #8:
score: 0
Accepted
time: 51ms
memory: 71552kb
input:
10 100 200 20000 33 77 70 12 88 3 29 59 63 41 75 18 42 83 96 44 67 73 79 48 92 54 78 93 21 14 24 72 91 25 71 97 2 89 76 20 37 95 68 87 39 31 5 100 9 23 74 80 7 27 50 69 52 82 81 85 56 84 34 32 17 36 11 16 8 57 49 30 60 86 62 99 13 19 98 43 6 4 46 58 64 45 51 53 10 28 90 26 40 94 35 22 61 15 47 1 55 ...
output:
1 4 2 3 2 4 0 2 1 1 1 0 0 4 0 4 3 2 2 1 4 0 4 0 2 2 4 2 2 0 2 2 1 0 0 1 3 2 2 0 0 0 3 2 0 1 4 1 2 2 3 1 3 0 2 1 1 4 2 1 0 0 3 0 0 2 0 2 4 3 0 4 0 0 3 0 2 2 0 4 3 4 2 3 2 0 2 0 1 1 2 1 2 1 4 0 1 0 1 2 0 2 4 1 0 2 4 2 3 1 4 2 0 2 0 2 0 2 2 0 1 2 1 2 0 3 2 1 2 1 1 4 1 1 1 2 1 2 2 1 0 2 0 1 0 1 1 1 0 2 ...
result:
ok 200000 lines
Test #9:
score: -100
Runtime Error
input:
1 316 632 200000 36 93 100 184 246 134 89 157 219 9 18 29 8 109 159 3 255 66 257 27 290 286 283 132 216 175 167 208 238 31 220 296 271 113 269 127 156 300 121 267 99 122 90 288 64 210 28 144 262 60 53 6 96 268 276 279 13 174 287 78 295 72 143 155 146 197 107 35 24 88 187 110 163 204 2 25 226 119 164...