# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
458254 | JovanB | Poklon (COCI17_poklon) | C++17 | 453 ms | 37312 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
const int N = 500001;
int last[N+5];
int bit[N+5];
void bit_add(int x, int val){
while(x <= N){
bit[x] += val;
x += x & -x;
}
}
int bit_get(int x){
int res = 0;
while(x){
res += bit[x];
x -= x & -x;
}
return res;
}
vector <pair <int, int>> vec[N+5];
map <int, int> pos;
int sol[N+5];
int main(){
ios_base::sync_with_stdio(false), cin.tie(0);
cout.precision(10);
cout << fixed;
int n, qrs;
cin >> n >> qrs;
for(int i=1; i<=n; i++){
int x;
cin >> x;
last[i] = pos[x];
pos[x] = i;
}
for(int i=1; i<=qrs; i++){
int l, r;
cin >> l >> r;
vec[r].push_back({l, i});
}
for(int i=1; i<=n; i++){
if(last[i]){
int j = last[i];
bit_add(j, 1);
if(last[j]){
int k = last[j];
bit_add(k, -2);
if(last[k]){
bit_add(last[k], 1);
}
}
}
for(auto qu : vec[i]){
int l = qu.first;
int ind = qu.second;
sol[ind] = bit_get(i) - bit_get(l - 1);
}
}
for(int i=1; i<=qrs; i++) cout << sol[i] << "\n";
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |