# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
1101122 | InvMOD | Poklon (COCI17_poklon) | C++14 | 1035 ms | 39356 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define gcd __gcd
#define sz(v) v.size()
#define pb push_back
#define pi pair<int,int>
#define all(v) (v).begin(), (v).end()
#define FOR(i, a, b) for(int i = (a); i <= (b); i++)
#define int long long
using ll = long long;
using ld = long double;
using ull = unsigned long long;
template<typename T> bool ckmx(T &a, T b){if(a < b) return a = b, true; return false;}
template<typename T> bool ckmn(T &a, T b){if(a > b) return a = b, true; return false;}
const int N = 5e5+5;
const ll MOD = 1e9+7;
const ll INF = 1e18;
const int SZ = 750;
struct Query{
int l,r,id;
};
int a[N], ans[N], mp[N], cnt[N], res = 0;
Query Q[N];
vector<int> tmp;
void add(int x){
if(cnt[mp[x]] == 2) res--;
cnt[mp[x]]++;
if(cnt[mp[x]] == 2) res++;
return;
}
void rem(int x){
if(cnt[mp[x]] == 2) res--;
cnt[mp[x]]--;
if(cnt[mp[x]] == 2) res++;
return;
}
void solve()
{
int n,q; cin >> n >> q;
FOR(i, 1, n){
cin >> a[i];
tmp.pb(a[i]);
}
tmp.pb(0);
sort(all(tmp));
tmp.erase(unique(all(tmp)), tmp.end());
FOR(i, 0, n){
int p = lower_bound(all(tmp), a[i]) - tmp.begin();
mp[i] = p;
}
FOR(i, 1, q){
cin >> Q[i].l >> Q[i].r;
Q[i].id = i;
}
sort(1 + Q, 1+q+Q, [&](Query x, Query y){
if(x.l/SZ != y.l/SZ) return x.l < y.l;
else return ((x.l/SZ)&1 ? (x.r < y.r) : (x.r > y.r));
});
res = 0;
int cl = 0, cr = 0;
add(0);
FOR(i, 1, q){
while(cr < Q[i].r) add(++cr);
while(cl < Q[i].l) rem(cl++);
while(cr > Q[i].r) rem(cr--);
while(cl > Q[i].l) add(--cl);
ans[Q[i].id] = res;
}
FOR(i, 1, q) cout << ans[i] <<"\n";
}
signed main()
{
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
#define name "InvMOD"
if(fopen(name".INP", "r")){
freopen(name".INP","r",stdin);
freopen(name".OUT","w",stdout);
}
int t = 1; //cin >> t;
while(t--) solve();
return 0;
}
컴파일 시 표준 에러 (stderr) 메시지
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |