当前位置:网站首页>Educational Codeforces Round 22 E. Army Creation
Educational Codeforces Round 22 E. Army Creation
2022-07-04 18:01: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;
}
边栏推荐
- Don't just learn Oracle and MySQL!
- PolyFit软件介绍
- 2022养生展,健康展,北京大健康展,健康产业展11月举办
- Shell 编程核心技术《二》
- 英特尔集成光电研究最新进展推动共封装光学和光互连技术进步
- 2022CoCa: Contrastive Captioners are Image-Text Fountion Models
- Safer, smarter and more refined, Chang'an Lumin Wanmei Hongguang Mini EV?
- 876. Intermediate node of linked list
- 长城证券开户安全吗 买股票怎么开户
- 牛客小白月赛7 E Applese的超能力
猜你喜欢

如何使用Async-Awati异步任務處理代替BackgroundWorker?

更安全、更智能、更精致,长安Lumin完虐宏光MINI EV?

Opencv functions and methods related to binary threshold processing are summarized for comparison and use

Oracle with as ora-00903: invalid table name multi report error

性能优化之关键渲染路径

Don't just learn Oracle and MySQL!

欧拉函数

Bi skills - permission axis

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

Introduction to polyfit software
随机推荐
英特尔集成光电研究最新进展推动共封装光学和光互连技术进步
1007 Maximum Subsequence Sum(25 分)(PAT甲级)
2019年蜀山区第十五届青少年信息学竞赛
牛客小白月赛7 E Applese的超能力
C # implementation defines a set of SQL statements that can be executed across databases in the middle of SQL (detailed explanation of the case)
OpenCV的二值化处理函数threshold()详解
PointNeXt:通过改进的模型训练和缩放策略审视PointNet++
一文掌握数仓中auto analyze的使用
更安全、更智能、更精致,长安Lumin完虐宏光MINI EV?
Shell programming core technology "four"
Lenovo explains in detail the green smart city digital twin platform for the first time to solve the difficulties of urban dual carbon upgrading
Unity adds a function case similar to editor extension to its script, the use of ContextMenu
FPGA timing constraint sharing 01_ Brief description of the four steps
Comment utiliser async awati asynchrone Task Handling au lieu de backgroundworker?
长城证券开户安全吗 买股票怎么开户
Unity editor extends C to traverse all pictures in folders and subdirectories
The page element is vertically and horizontally centered, realizing the vertical and horizontal centering of known or unknown width.
The difference and usage between substr (), slice (), and substring () in the string interception methods of "understand series after reading"
Pytest 可视化测试报告之 Allure
启牛开的证券账户安全吗?