# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
577596 |
2022-06-15T06:20:02 Z |
Ronin13 |
Poklon (COCI17_poklon) |
C++14 |
|
2091 ms |
17140 KB |
#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;
}
Compilation message
poklon.cpp: In function 'int main()':
poklon.cpp:73:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<mo>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
73 | for(int i = 0; i < qv.size(); i++){
| ~~^~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Correct |
2 ms |
340 KB |
Output is correct |
4 |
Correct |
6 ms |
608 KB |
Output is correct |
5 |
Correct |
149 ms |
3400 KB |
Output is correct |
6 |
Correct |
160 ms |
3648 KB |
Output is correct |
7 |
Correct |
495 ms |
7004 KB |
Output is correct |
8 |
Correct |
954 ms |
11024 KB |
Output is correct |
9 |
Correct |
1438 ms |
13652 KB |
Output is correct |
10 |
Correct |
2091 ms |
17140 KB |
Output is correct |