# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
990020 |
2024-05-29T11:17:59 Z |
Has2008 |
Poklon (COCI17_poklon) |
C++17 |
|
5000 ms |
25476 KB |
#include "bits/stdc++.h"
using namespace std;
#define int long long
#define mod 1000000007
const int maxn = 500005;
int n, q, N = 1;
int arr[maxn], tree[maxn * 4];
int query(int n, int ql, int qr, int l, int r)
{
if(l >= ql && r <= qr) return tree[n];
if(l > qr || r < ql) return 0;
int md = (l + r) / 2;
return query(n * 2, ql, qr, l, md) + query(n * 2 + 1, ql, qr, md + 1, r);
}
int update(int u, int v)
{
u += N;
tree[u] = v;
u /= 2;
while (u > 0)
{
tree[u] = tree[u * 2] + tree[u * 2 + 1];
u /= 2;
}
}
signed main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
cin >> n >> q;
while (N < n) N *= 2;
for(int i = 0; i < n; i++) cin >> arr[i];
vector < pair < int, int >> v, o;
while (q--)
{
int l, r;
cin >> l >> r;
v.push_back({r, l});
o.push_back({l, r});
}
sort(v.begin(), v.end());
map < int, vector < int >> mp;
map < pair < int, int >, int > ans;
int indx = 0;
for(int i = 0; i < n; i++)
{
vector < int > vv = mp[arr[i]];
if(vv.size() == 0) mp[arr[i]].push_back(i);
else if(vv.size() == 1)
{
update(vv[0], 1);
mp[arr[i]].push_back(i);
}
else if(vv.size() == 2)
{
update(vv[0], -1);
update(vv[1], 1);
mp[arr[i]].push_back(i);
}
else
{
update(vv[0], 0);
update(vv[1], -1);
update(vv[2], 1);
mp[arr[i]].clear();
mp[arr[i]].push_back(vv[1]);
mp[arr[i]].push_back(vv[2]);
mp[arr[i]].push_back(i);
}
while (indx != q && v[indx].first == i + 1)
{
ans[{v[indx].second, v[indx].first}] = query(1, v[indx].second - 1, v[indx].first - 1, 0, N - 1);
indx++;
}
}
for(int i = 0; i < o.size(); i++) cout << ans[{o[i].first, o[i].second}] << endl;
}
Compilation message
poklon.cpp: In function 'long long int update(long long int, long long int)':
poklon.cpp:32:1: warning: no return statement in function returning non-void [-Wreturn-type]
32 | }
| ^
poklon.cpp: In function 'int main()':
poklon.cpp:96:22: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<std::pair<long long int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
96 | for(int i = 0; i < o.size(); i++) cout << ans[{o[i].first, o[i].second}] << endl;
| ~~^~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
5038 ms |
2396 KB |
Time limit exceeded |
2 |
Execution timed out |
5072 ms |
2396 KB |
Time limit exceeded |
3 |
Execution timed out |
5074 ms |
2396 KB |
Time limit exceeded |
4 |
Execution timed out |
5054 ms |
2652 KB |
Time limit exceeded |
5 |
Execution timed out |
5031 ms |
7924 KB |
Time limit exceeded |
6 |
Execution timed out |
5017 ms |
7720 KB |
Time limit exceeded |
7 |
Execution timed out |
5063 ms |
12972 KB |
Time limit exceeded |
8 |
Execution timed out |
5015 ms |
20128 KB |
Time limit exceeded |
9 |
Execution timed out |
5037 ms |
23440 KB |
Time limit exceeded |
10 |
Execution timed out |
5040 ms |
25476 KB |
Time limit exceeded |