# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
577596 | Ronin13 | Poklon (COCI17_poklon) | C++14 | 2091 ms | 17140 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
#define ll long long
#define ull unsigned ll
#define f first
#define s second
#define pii pair<int,int>
#define pll pair<ll,ll>
#define pb push_back
#define epb emplace_back
using namespace std;
struct mo{
int l, r, ind;
int bl;
mo(int l, int r, int ind) : l(l), r (r), ind(ind){
bl = (l - 1) / 500;
}
mo(){
l = r = ind = 0;
bl = 0;
}
};
bool operator < (mo a, mo b){
return a.bl < b.bl || (a.bl == b.bl && a.r < b.r);
}
vector <mo> qv;
int used[1000001];
int a[1000001];
int good;
void add(int ind){
int x = a[ind];
if(used[x] == 2) good--;
used[x]++;
if(used[x] == 2) good++;
}
void rem(int ind){
int x = a[ind];
if(used[x] == 2) good--;
used[x]--;
if(used[x] == 2) good++;
}
int main(){
ios_base::sync_with_stdio(false); cin.tie(0);
int n; cin >> n;
int q; cin >> q;
int b[n + 1];
map <int,int> mp;
for(int i= 1; i <= n; i++){
cin >> a[i];
b[i] = a[i];
}
sort(b + 1, b + 1 + n);
for(int i = 1; i <= n; i++){
mp[b[i]] = i;
}
for(int i = 1; i <= n; i++){
a[i] = mp[a[i]];
}
int mo_l, mo_r;
mo_l = 1, mo_r = 0;
for(int i = 1; i <= q; i++){
int l, r; cin >> l >> r;
qv.epb(l, r, i);
}
sort(qv.begin(), qv.end());
vector <int> ans(q + 1);
for(int i = 0; i < qv.size(); i++){
int l = qv[i].l, r = qv[i].r, ind = qv[i].ind;
while(mo_r < r){
mo_r++;
add(mo_r);
}
while(mo_r > r){
rem(mo_r);
mo_r--;
}
while(mo_l < l){
rem(mo_l);
mo_l++;
}
while(mo_l > l){
mo_l--;
add(mo_l);
}
ans[ind] = good;
}
for(int i= 1; i <= q; i++) cout << ans[i] << "\n";
return 0;
}
컴파일 시 표준 에러 (stderr) 메시지
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |