Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- using namespace std;
- const int N = 2e5;
- int arr[N + 2], cls[N + 1], cnt[N + 1];
- int nDwarf, numType;
- void addSnack(int x){
- if(x < 1 || x > nDwarf){
- return;
- }
- if(cnt[x] == 0){
- ++numType;
- }
- ++cnt[x];
- }
- void removeSnack(int x){
- if(x < 1 || x > nDwarf){
- return;
- }
- --cnt[x];
- if(cnt[x] == 0){
- --numType;
- }
- }
- int main(){
- int nSnack, Q;
- scanf("%d%d%d", &nSnack, &nDwarf, &Q);
- for(int i = 1; i <= nSnack; ++i){
- scanf("%d", &arr[i]);
- }
- numType = 0;
- int mnIdx = 0;
- for(int i = 1; i <= nSnack; ++i){
- while(numType < nDwarf && mnIdx <= nSnack){
- addSnack(arr[mnIdx + 1]);
- ++mnIdx;
- }
- cls[i] = mnIdx;
- removeSnack(arr[i]);
- }
- while(Q--){
- int l, r;
- scanf("%d%d", &l, &r);
- if(r >= cls[l]){
- cout << "YES\n";
- } else {
- cout << "NO\n";
- }
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement