当前位置:网站首页>Educational Codeforces Round 22 E. Army Creation
Educational Codeforces Round 22 E. Army Creation
2022-07-04 19:34:00 【不吃土司邊】
#include <iostream>
#include <stdio.h>
#include <string.h>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <vector>
#include <math.h>
#include <bitset>
#include <algorithm>
using namespace std;
#define X first
#define Y second
#define eps 1e-2
#define gcd __gcd
#define pb push_back
#define PI acos(-1.0)
#define lowbit(x) (x)&(-x)
#define bug printf("!!!!!\n");
#define mem(x,y) memset(x,y,sizeof(x))
typedef long long LL;
typedef long double LD;
typedef pair<int,int> pii;
typedef unsigned long long uLL;
const int N = 1e5+2;
const int INF = 1<<30;
const int mod = 1e9+7;
std::vector<int> v[N];
struct node{
int l,r,sum;
}t[N<<5];
int tot=0;
int build(int p,int l,int r){
p=++tot;
if(l==r) return p;
int mid=(l+r)>>1;
t[p].l=build(p,l,mid);
t[p].r=build(p,mid+1,r);
return p;
}
int update(int p,int l,int r,int x){
t[++tot]=t[p];p=tot;t[p].sum++;
if(l==r) return p;
int mid=(l+r)>>1;
if(x<=mid) t[p].l=update(t[p].l,l,mid,x);
else t[p].r=update(t[p].r,mid+1,r,x);
return p;
}
int query(int p1,int p2,int l,int r,int from,int to){
if(from<=l&&to>=r) return t[p2].sum-t[p1].sum;
int mid=(l+r)>>1,ans=0;
if(from<=mid) ans+=query(t[p1].l,t[p2].l,l,mid,from,to);
if(to>=mid+1) ans+=query(t[p1].r,t[p2].r,mid+1,r,from,to);
return ans;
}
int n,k,a[N],q,rt[N];
void solve(){
scanf("%d%d",&n,&k);rt[0]=build(1,0,n);
for(int i=1;i<=n;i++){
scanf("%d",&a[i]),v[a[i]].push_back(i);
int sz=v[a[i]].size();
int pos=(sz>k?v[a[i]][sz-1-k]:0);
rt[i]=update(rt[i-1],0,n,pos);
}
// cout<<tot<<endl;
scanf("%d",&q);
int last=0;
// cout<<t[18].sum<<endl;
// cout<<rt[1]<<" "<<rt[2]<<endl;
while(q--){
int l,r;scanf("%d%d",&l,&r);
l=((l+last)%n)+1;
r=((r+last)%n)+1;
if(l>r) swap(l,r);
// cout<<l<<" "<<r<<endl;
last=query(rt[l-1],rt[r],0,n,0,l-1);
cout<<last<<endl;
}
return;
}
int main()
{
// freopen("in.txt","r",stdin);
// freopen("out.txt","w",stdout);
// ios::sync_with_stdio(false);
int t = 1;
//scanf("%d",&t);
while(t--){
// printf("Case %d: ",cas++);
solve();
}
return 0;
}
边栏推荐
猜你喜欢

Lenovo explains in detail the green smart city digital twin platform for the first time to solve the difficulties of urban dual carbon upgrading

Pytorch学习(四)

Comment utiliser async awati asynchrone Task Handling au lieu de backgroundworker?

One question per day (2022-07-02) - Minimum refueling times

大div中有多个div,这些div在同一行显示,溢出后产生滚动条而不换行

自由小兵儿
Summary and sorting of 8 pits of redis distributed lock

升级智能开关,“零火版”、“单火”接线方式差异有多大?

LM10丨余弦波动顺势网格策略

Master the use of auto analyze in data warehouse
随机推荐
Go microservice (II) - detailed introduction to protobuf
An example of multi module collaboration based on NCF
YOLOv5s-ShuffleNetV2
Lm10 cosine wave homeopathic grid strategy
Oracle with as ora-00903: invalid table name multi report error
FPGA timing constraint sharing 01_ Brief description of the four steps
性能优化之关键渲染路径
How test engineers "attack the city" (Part 2)
Shell programming core technology "three"
Summary and sorting of 8 pits of redis distributed lock
HDU 6440 2018中国大学生程序设计网络选拔赛
1009 Product of Polynomials(25 分)(PAT甲级)
OpenCV的二值化处理函数threshold()详解
Unity编辑器扩展C#遍历文件夹以及子目录下的所有图片
联想首次详解绿色智城数字孪生平台 破解城市双碳升级难点
C#实现定义一套中间SQL可以跨库执行的SQL语句(案例详解)
Have you guys ever used CDC direct Mysql to Clickhouse
Crawler (6) - Web page data parsing (2) | the use of beautifulsoup4 in Crawlers
Technologie de base de la programmation Shell IV
.NET ORM框架HiSql实战-第二章-使用Hisql实现菜单管理(增删改查)