# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
818067 | vjudge1 | Poklon (COCI17_poklon) | C++17 | 1020 ms | 23000 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
#define ll long long
#define ull unsigned ll
#define pb push_back
#define pa pair<int, int>
#define pall pair<ll, int>
#define fi first
#define se second
#define TASK "test"
#define Size(x) (int) x.size()
#define all(x) x.begin(), x.end()
using namespace std;
template<typename T1, typename T2> bool mini (T1 &a, T2 b) {if(a > b) a = b; else return 0; return 1;}
template<typename T1, typename T2> bool maxi (T1 &a, T2 b) {if(a < b) a = b; else return 0; return 1;}
const int MOD = 1e9 + 7;
const int LOG = 20;
const int maxn = 5e5 + 7;
const ll oo = 1e18 + 69;
const int sz = 800;
int n, q, a[maxn], res[maxn], l, r, cnt, mp[maxn];
struct query {
int l, r, id;
friend bool operator < (query &a, query &b) {
if(a.l / sz == b.l / sz) return ((a.l / sz) & 1) == 0 ? a.r < b.r:a.r > b.r;
return a.l / sz < b.l / sz;
}
};
vector<query> que;
void add(int i) {
mp[a[i]]++;
if(mp[a[i]] == 3) cnt--;
if(mp[a[i]] == 2) cnt++;
}
void sub(int i) {
mp[a[i]]--;
if(mp[a[i]] == 2) cnt++;
if(mp[a[i]] == 1) cnt--;
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
//freopen(TASK".inp", "r", stdin);
//freopen(TASK".out", "w", stdout);
cin>>n>>q;
vector<int> val;
for(int i = 1; i <= n; i++) {
cin>>a[i];
val.pb(a[i]);
}
sort(all(val));
val.erase(unique(all(val)), val.end());
for(int i = 1; i <= n; i++) {
a[i] = lower_bound(all(val), a[i]) - val.begin();
}
for(int i = 0; i < q; i++) {
cin>>l>>r;
que.pb({l, r, i});
}
sort(all(que));
l = 1, r = 0, cnt = 0;
for(auto e:que) {
while(r < e.r) add(++r);
while(l > e.l) add(--l);
while(r > e.r) sub(r--);
while(l < e.l) sub(l++);
res[e.id] = cnt;
}
for(int i = 0; i < q; i++) cout<<res[i]<<"\n";
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |