QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#885139 | #9731. Fuzzy Ranking | XJK404 | WA | 15ms | 14000kb | C++14 | 1.9kb | 2025-02-06 14:09:39 | 2025-02-06 14:09:45 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
#define itn int
#define tin int
#define nit int
#define longlong long long
typedef long long ll;
typedef unsigned long long ull;
ll l[1145141],r[1145141],a[1145141];
int cnt,minr[1145141],maxr[1145141];
ll sum[1145141];
ll query(ll le,ll re){
if(le>=l[cnt]||re<=r[1]){
return (re-le)*(re-le+1)/2;
}
int al=1e9,ar=0,L=1,R=cnt;
while(L<=R){
int mid=(L+R)/2;
if(l[mid]>=le){
al=min(al,mid);
R=mid-1;
}
else{
L=mid+1;
}
}
L=1,R=cnt;
while(L<=R){
int mid=(L+R)/2;
if(r[mid]<=re){
ar=max(ar,mid);
L=mid+1;
}
else{
R=mid-1;
}
}
if(al==1e9||ar==0){
return (re-le)*(re-le+1)/2;
}
if(al>ar){
return (re-le)*(re-le+1)/2;
}
ll s=sum[ar]-sum[al-1];
if(l[al]-1>=le)
s+=(l[al]-1-le)*(l[al]-le)/2;
if(r[ar]+1<=re)
s+=(re-1-r[ar])*(re-r[ar])/2;
return s;
}
void solve() {
int n,k,q;
cin>>n>>k>>q;
for(int i=1;i<=n;i++){
l[i]=0;
r[i]=0;
a[i]=0;
}
for(int i=1;i<=n;i++){
minr[i]=1e9;
maxr[i]=0;
sum[i]=0;
}
int I;
for(int i=1;i<=k;i++){
for(int j=1;j<=n;j++){
cin>>a[j];
minr[a[j]]=min(minr[a[j]],j);
maxr[a[j]]=max(maxr[a[j]],j);
}
}
cnt=1;
int nl=minr[a[1]],nr=maxr[a[1]];
l[1]=1,r[1]=nr;
for(int i=2;i<=n;i++){
if(minr[a[i]]>nr){
cnt++;
l[cnt]=r[cnt-1]+1;
nr=maxr[a[i]];
r[cnt]=nr;
}
else{
if(maxr[a[i]]>nr){
nr=maxr[a[i]];
r[cnt]=nr;
}
}
}
for(int i=1;i<=cnt;i++){
ll siz=r[i]-l[i];
sum[i]=siz*(siz+1)/2+sum[i-1];
}
int v=0,id,L,R;
for(int i=1;i<=q;i++){
cin>>id>>L>>R;
id=(id+v)%k+1;
L=(L+v)%n+1;
R=(R+v)%n+1;
v=query(L,R);
cout<<v<<endl;
if(v==15){
cout<<L<<' '<<R<<endl;
}
}
}
int main() {
ios::sync_with_stdio(false);
cin.tie(0);cout.tie(0);
int T;
T = 1;
cin >> T;
while(T--) {
solve();
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 14000kb
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: 13924kb
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 3 8 0 3 15 3 8 15 8 2 18 3 6 1 6 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 21 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 1 0 0 0 0 0 0 0 0 0 0 3 0 0 1 3 1 0 0 ...
result:
wrong answer 31st lines differ - expected: '0', found: '3 8'