# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
246087 | Vimmer | Poklon (COCI17_poklon) | C++14 | 1398 ms | 13352 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
//#pragma GCC optimize("unroll-loops")
//#pragma GCC optimize("-O3")
//#pragma GCC optimize("Ofast")
//#pragma GCC optimize("fast-math")
//#pragma GCC optimize("no-stack-protector")
#define F first
#define S second
#define sz(x) int(x.size())
#define pb push_back
#define pf push_front
#define N 100100
#define M ll(1e9 + 7)
#define inf 1e9 + 1e9
using namespace std;
//using namespace __gnu_pbds;
typedef long double ld;
typedef long long ll;
typedef short int si;
typedef array <int, 3> a3;
//typedef tree <int, null_type, less_equal<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
vector <a3> qr;
int kol[500005], a[500005], koler = 0;
bool cmp(a3 a, a3 b)
{
int lx = a[0] / 700;
int rx = b[0] / 700;
if (lx != rx) return lx < rx;
if (lx % 2) return a[1] > b[1];
return a[1] < b[1];
}
void del(int x)
{
kol[a[x]]--;
if (kol[a[x]] == 1) koler--;
if (kol[a[x]] == 2) koler++;
}
void add(int x)
{
kol[a[x]]++;
if (kol[a[x]] == 3) koler--;
if (kol[a[x]] == 2) koler++;
}
int main()
{
////freopen("input.txt", "r", stdin); //freopen("output4.txt", "w", stdout);
ios_base::sync_with_stdio(0); istream::sync_with_stdio(0); cin.tie(0); cout.tie(0);
int n, k;
cin >> n >> k;
vector <int> pr(n);
for (int i = 0; i < n; i++) {cin >> a[i]; pr[i] = a[i];}
sort(pr.begin(), pr.end());
pr.resize(unique(pr.begin(), pr.end()) - pr.begin());
for (int i = 0; i < n; i++) a[i] = lower_bound(pr.begin(), pr.end(), a[i]) - pr.begin();
for (int i = 0; i < k; i++) {int x, y; cin >> x >> y; qr.pb({x, y, i});}
sort(qr.begin(), qr.end(), cmp);
int ans[n], L = 0, R = -1;
for (int i = 0; i < k; i++)
{
int nm = qr[i][2], l = qr[i][0], r = qr[i][1];
l--; r--;
while (R < r) {R++; add(R);}
while (L < l) {del(L); L++;}
while (R > r) {del(R); R--;}
while (L > l) {L--; add(L);}
ans[nm] = koler;
}
for (int i = 0; i < k; i++) cout << ans[i] << '\n';
}
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |