Caso # | Resultado | Tiempo | Memoria |
---|---|---|---|
#1 |
Correcto
|
0.008 s | 1 KBi |
#2 |
Correcto
|
0.005 s | 1 KBi |
#3 |
Correcto
|
0.012 s | 0 KBi |
#4 |
Correcto
|
0.231 s | 6 KBi |
#5 |
Correcto
|
0.68 s | 6 KBi |
#6 |
Correcto
|
0.263 s | 11 KBi |
#7 |
Correcto
|
0.334 s | 11 KBi |
#8 |
Correcto
|
0.356 s | 11 KBi |
/// Write by Daniel Perez .PERAPRO #include<bits/stdc++.h> using namespace std; #define fast_io ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); #define pb push_back #define ff first #define ss second typedef long long ll; typedef unsigned long long ull; typedef long double ld; using vi=vector<int>; using vl=vector<ll>; using pii=pair<int,int>; char el = '\n'; char esp = ' '; template<class T> bool ckmin(T& a, const T& b) { return b < a ? a = b, 1 : 0; } template<class T> bool ckmax(T& a, const T& b) { return a < b ? a = b, 1 : 0; } ostream& operator<<(ostream& os, const vector<int> &v){ for(auto const &i: v){ os<<i<<" "; } os<<'\n'; return os; } string yes="YES"; string no="NO"; int main(){ fast_io; /* freopen("input.txt","r",stdin); freopen("output.txt","w",stdout); */ int n; cin>>n; vi v(n); for(int i=0;i<n;i++){ cin>>v[i]; } vi compress(v); //cout<<compress; sort(compress.begin(),compress.end()); compress.erase(unique(compress.begin(),compress.end()),compress.end()); //cout<<compress; vi cnt(compress.size()); vector<set<pii>> solve(compress.size()); for(int i=0;i<n;i++){ int x = lower_bound(compress.begin(),compress.end(),v[i]) - compress.begin(); cnt[x]++; solve[x].insert({i,cnt[x]}); } int querys,l,r,x,element; cin>>querys; while(querys--){ cin>>l>>r>>element; x = lower_bound(compress.begin(),compress.end(),element) - compress.begin(); if(x == compress.size() || compress[x] != element){ cout<<0<<el; continue; } auto it = solve[x].lower_bound({l,0}); if(it == solve[x].end() || it->ff > r){ // Hay al menos un elemento en el rango [l, r] cout<<0<<el; continue; } pii left = *it; it = solve[x].lower_bound({r,0}); if(it == solve[x].end() || it->ff > r) it--; pii right = *it; cout<<right.ss - left.ss + 1<<el; } } /* */