# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
577599 | keta_tsimakuridze | Poklon (COCI17_poklon) | C++14 | 574 ms | 41748 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define pii pair<int,int>
#define f first
#define s second
#define endl "\n"
const int N = 5e5 + 5, mod = 1e9 + 7; //!
int t, a[N], ans[N], lst[N], tree[N], n;
vector<pii> x[N];
map<int,int> f;
void upd(int id, int t) {
for(id; id <= n; id += id & (-id)) tree[id] += t;
}
int get(int id) {
int ans = 0;
for(id; id >= 1; id -= id & (-id)) ans += tree[id];
return ans;
}
main() {
ios_base::sync_with_stdio(false),cin.tie(0),cout.tie(0);
int q;
cin >> n >> q;
for(int i = 1; i <= n; i++) {
cin >> a[i];
}
for(int i = 1; i <= q; i++) {
int l, r;
cin >> l >> r;
x[l].push_back({r, i});
}
for(int i = n; i >= 1; i--) {
if(f[a[i]]) {
upd(f[a[i]], 1);
if(lst[f[a[i]]]) upd(lst[f[a[i]]], -2) ;
if(lst[lst[f[a[i]]]]) upd(lst[lst[f[a[i]]]], 1);
}
lst[i] = f[a[i]];
f[a[i]] = i;
for(int j = 0; j < x[i].size(); j++) {
ans[x[i][j].s] = get(x[i][j].f);
}
}
for(int i = 1; i <= q; i++) cout << ans[i] << "\n";
}
컴파일 시 표준 에러 (stderr) 메시지
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |