update
This commit is contained in:
parent
11660860e7
commit
ac313d36a3
81
src/P1972/P1972.cpp
Normal file
81
src/P1972/P1972.cpp
Normal file
@ -0,0 +1,81 @@
|
||||
#include <algorithm>
|
||||
#include <cstdint>
|
||||
#include <iostream>
|
||||
#include <istream>
|
||||
|
||||
using ll = int64_t;
|
||||
using std::cin, std::cout;
|
||||
|
||||
const ll maxn = 1e6+5;
|
||||
ll n, kds[maxn], m, anss[maxn], viss[maxn], bits[maxn];
|
||||
|
||||
struct Sch{
|
||||
ll l, r, pos;
|
||||
}schs[maxn];
|
||||
|
||||
ll lb(const ll &v){
|
||||
return v&(-v);
|
||||
}
|
||||
|
||||
void tadd(ll idx, const ll &v){
|
||||
while(idx<=n){
|
||||
bits[idx]+=v;
|
||||
idx+=lb(idx);
|
||||
}
|
||||
}
|
||||
|
||||
ll tpsch(ll idx){
|
||||
ll res{};
|
||||
while(idx!=0){
|
||||
res+=bits[idx];
|
||||
idx-=lb(idx);
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
||||
#define DB(v){cout<<#v<<": "<<(v)<<'\n';};
|
||||
|
||||
int main(){
|
||||
std::iostream::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr);
|
||||
|
||||
cin>>n;
|
||||
for(ll i{1};i<=n;i++){
|
||||
cin>>kds[i];
|
||||
}
|
||||
cin>>m;
|
||||
for(ll i{1};i<=m;i++){
|
||||
cin>>schs[i].l>>schs[i].r;
|
||||
schs[i].pos=i;
|
||||
}
|
||||
std::sort(schs+1, schs+1+m, [](const Sch &a, const Sch &b)->bool{
|
||||
return a.r<b.r;
|
||||
});
|
||||
ll nm{1};
|
||||
for(ll i{1};i<=n;i++){
|
||||
if((bool)viss[kds[i]]){
|
||||
tadd(viss[kds[i]], -1);
|
||||
viss[kds[i]]=i;
|
||||
tadd(i, 1);
|
||||
}else{
|
||||
viss[kds[i]]=i;
|
||||
tadd(i, 1);
|
||||
}
|
||||
if(i==schs[nm].r){
|
||||
// cout<<"{ ";
|
||||
// for(ll i{1}; i<=schs[nm].r; i++){
|
||||
// cout<<tpsch(i)-tpsch(i-1)<<", ";
|
||||
// }
|
||||
// cout<<"}\n";
|
||||
// DB(schs[nm].pos)
|
||||
// DB(tpsch(schs[nm].l-1));
|
||||
// DB(tpsch(schs[nm].r))
|
||||
|
||||
anss[schs[nm].pos] = tpsch(schs[nm].r) - tpsch(schs[nm].l-1);
|
||||
if(nm==m)break;
|
||||
nm++;
|
||||
}
|
||||
}
|
||||
for(ll i{1};i<=m;i++){
|
||||
cout<<anss[i]<<'\n';
|
||||
}
|
||||
}
|
3003
src/P1972/P1972_1.in
Normal file
3003
src/P1972/P1972_1.in
Normal file
File diff suppressed because one or more lines are too long
3000
src/P1972/P1972_1.out
Normal file
3000
src/P1972/P1972_1.out
Normal file
File diff suppressed because it is too large
Load Diff
Loading…
Reference in New Issue
Block a user