当前位置:网站首页>Educational codeforces round 22 E. Army Creation
Educational codeforces round 22 E. Army Creation
2022-07-04 19:34:00 【Pas de toast.】
#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;
}
边栏推荐
- Bi skills - permission axis
- Master the use of auto analyze in data warehouse
- 1007 Maximum Subsequence Sum(25 分)(PAT甲级)
- 指定输出的字符集
- 有关架构设计的个人思考(本文后续不断修改更新)
- MySQL数据库基本操作-DDL | 黑马程序员
- Detailed explanation of the binary processing function threshold() of opencv
- 1009 Product of Polynomials(25 分)(PAT甲级)
- Unity给自己的脚本添加类似编辑器扩展的功能案例ContextMenu的使用
- C # implementation defines a set of SQL statements that can be executed across databases in the middle of SQL (detailed explanation of the case)
猜你喜欢
SSRS筛选器的IN运算(即包含于)用法
一文掌握数仓中auto analyze的使用
The latest progress of Intel Integrated Optoelectronics Research promotes the progress of CO packaging optics and optical interconnection technology
整理混乱的头文件,我用include what you use
用实际例子详细探究OpenCV的轮廓绘制函数drawContours()
Don't just learn Oracle and MySQL!
线上数据库迁移的几种方法
Pointnet/Pointnet++点云数据集处理并训练
读写关闭的channel是啥后果?
LM10丨余弦波动顺势网格策略
随机推荐
1008 Elevator(20 分)(PAT甲级)
测试工程师如何“攻城”(上)
一文掌握数仓中auto analyze的使用
2021 合肥市信息学竞赛小学组
Shell programming core technology II
The CDC of sqlserver can read the data for the first time, but it can't read the data after adding, deleting and modifying. What's the reason
Safer, smarter and more refined, Chang'an Lumin Wanmei Hongguang Mini EV?
安徽 中安在线文旅频道推出“跟着小编游安徽”系列融媒体产品
数组中的第K个最大元素
The page element is vertically and horizontally centered, realizing the vertical and horizontal centering of known or unknown width.
1672. 最富有客户的资产总量
1009 Product of Polynomials(25 分)(PAT甲级)
Hough Transform 霍夫变换原理
长城证券开户安全吗 买股票怎么开户
添加命名空间声明
Technologie de base de la programmation Shell IV
牛客小白月赛7 谁是神箭手
An example of multi module collaboration based on NCF
Go microservice (II) - detailed introduction to protobuf
线上数据库迁移的几种方法