Submission #1023764

# Submission time Handle Problem Language Result Execution time Memory
1023764 2024-07-15T06:06:44 Z cnn008 Index (COCI21_index) C++17
110 / 110
886 ms 10068 KB
#include "bits/stdc++.h"
using namespace std;

#ifdef N_N_C
#include "debug.h"
#else
#define cebug(...) "Arya"
#endif

#define ll long long

const int N=2e5+5;
const int mod=1e9+7;
const int block=350;

struct Query{
	int l,r,id;
	bool operator < (const Query &o){
		if(this->l/block==o.l/block) return this->r<o.r;
		return this->l/block<o.l/block;
	}
}q[N];
struct BIT{
	#define gb(x) (x&(-x))
   	int n;
   	vector <int> bit;
   	void init(int _n){
   		bit.resize(_n,0);
   		n=_n;
   	}
   	void update(int pos, int val){
   		int i=pos;
      	for (; i; i-=gb(i)) bit[i]+=val;
   	}
   	int get(int pos){
    	int ans=0,i=pos;
      	for (; i<n; i+=gb(i)) ans+=bit[i];
      	return ans;
   	}
}fw;
int n,m,a[N],ans,saki[N];
void add(int i){
	fw.update(a[i],1);
	while(fw.get(ans+1)>=ans+1) ans++;
}
void del(int i){
	fw.update(a[i],-1);
	while(fw.get(ans)<ans) ans--;
}
void sol(){
	fw.init(N);
	cin>>n>>m;
	for(int i=1; i<=n; i++) cin>>a[i];
	for(int i=1; i<=m; i++) cin>>q[i].l>>q[i].r,q[i].id=i;
	sort(q+1,q+m+1);
	int l=1,r=0;
	for(int i=1; i<=m; i++){
		while(r<q[i].r) add(++r);
		while(r>q[i].r) del(r--);
		while(l<q[i].l) del(l++);
		while(l>q[i].l) add(--l);
		saki[q[i].id]=ans;
	}
	for(int i=1; i<=m; i++) cout<<saki[i]<<"\n";
}
signed main(){
	ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    // freopen(".inp", "r", stdin);
    // freopen(".out", "w", stdout);
    int tt=1;
    //cin>>tt; 
    while(tt--){
    	sol();
    }
    cerr << "\nTime elapsed: " << 1000.0 * clock() / CLOCKS_PER_SEC << " ms.\n";
    return 0;
}
/**  /\_/\
*   (= ._.)
*   / >💖 \>💕
**/

Compilation message

index.cpp:79:9: warning: "/*" within comment [-Wcomment]
   79 | /**  /\_/\
      |
# Verdict Execution time Memory Grader output
1 Correct 2 ms 1116 KB Output is correct
2 Correct 2 ms 1116 KB Output is correct
3 Correct 2 ms 1116 KB Output is correct
4 Correct 2 ms 1116 KB Output is correct
5 Correct 2 ms 1116 KB Output is correct
6 Correct 2 ms 1116 KB Output is correct
7 Correct 2 ms 1116 KB Output is correct
8 Correct 2 ms 1116 KB Output is correct
9 Correct 1 ms 1116 KB Output is correct
10 Correct 2 ms 1116 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 1116 KB Output is correct
2 Correct 2 ms 1116 KB Output is correct
3 Correct 2 ms 1116 KB Output is correct
4 Correct 2 ms 1116 KB Output is correct
5 Correct 2 ms 1116 KB Output is correct
6 Correct 2 ms 1116 KB Output is correct
7 Correct 2 ms 1116 KB Output is correct
8 Correct 2 ms 1116 KB Output is correct
9 Correct 1 ms 1116 KB Output is correct
10 Correct 2 ms 1116 KB Output is correct
11 Correct 187 ms 3156 KB Output is correct
12 Correct 179 ms 3152 KB Output is correct
13 Correct 182 ms 3308 KB Output is correct
14 Correct 185 ms 3156 KB Output is correct
15 Correct 177 ms 3152 KB Output is correct
16 Correct 182 ms 3156 KB Output is correct
17 Correct 189 ms 3152 KB Output is correct
18 Correct 203 ms 3300 KB Output is correct
19 Correct 182 ms 3152 KB Output is correct
20 Correct 197 ms 3408 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 1116 KB Output is correct
2 Correct 2 ms 1116 KB Output is correct
3 Correct 2 ms 1116 KB Output is correct
4 Correct 2 ms 1116 KB Output is correct
5 Correct 2 ms 1116 KB Output is correct
6 Correct 2 ms 1116 KB Output is correct
7 Correct 2 ms 1116 KB Output is correct
8 Correct 2 ms 1116 KB Output is correct
9 Correct 1 ms 1116 KB Output is correct
10 Correct 2 ms 1116 KB Output is correct
11 Correct 187 ms 3156 KB Output is correct
12 Correct 179 ms 3152 KB Output is correct
13 Correct 182 ms 3308 KB Output is correct
14 Correct 185 ms 3156 KB Output is correct
15 Correct 177 ms 3152 KB Output is correct
16 Correct 182 ms 3156 KB Output is correct
17 Correct 189 ms 3152 KB Output is correct
18 Correct 203 ms 3300 KB Output is correct
19 Correct 182 ms 3152 KB Output is correct
20 Correct 197 ms 3408 KB Output is correct
21 Correct 854 ms 10004 KB Output is correct
22 Correct 834 ms 10068 KB Output is correct
23 Correct 842 ms 10032 KB Output is correct
24 Correct 839 ms 10040 KB Output is correct
25 Correct 847 ms 9868 KB Output is correct
26 Correct 867 ms 9868 KB Output is correct
27 Correct 837 ms 9864 KB Output is correct
28 Correct 866 ms 9884 KB Output is correct
29 Correct 886 ms 9868 KB Output is correct
30 Correct 858 ms 9868 KB Output is correct