# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
990011 |
2024-05-29T11:07:22 Z |
Has2008 |
Poklon (COCI17_poklon) |
C++17 |
|
5000 ms |
35460 KB |
#include "bits/stdc++.h"
#define int long long
#define mod 1000000007
using namespace std;
const int maxn = 500005;
int N;
int n, q;
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;
N = 1 << (int)ceil(log2(n) + 1);
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:34:1: warning: no return statement in function returning non-void [-Wreturn-type]
34 | }
| ^
poklon.cpp: In function 'int main()':
poklon.cpp:98: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]
98 | 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 |
5025 ms |
2396 KB |
Time limit exceeded |
2 |
Execution timed out |
5033 ms |
2396 KB |
Time limit exceeded |
3 |
Execution timed out |
5032 ms |
2392 KB |
Time limit exceeded |
4 |
Execution timed out |
5040 ms |
2908 KB |
Time limit exceeded |
5 |
Execution timed out |
5041 ms |
9136 KB |
Time limit exceeded |
6 |
Execution timed out |
5074 ms |
9512 KB |
Time limit exceeded |
7 |
Execution timed out |
5035 ms |
18604 KB |
Time limit exceeded |
8 |
Execution timed out |
5039 ms |
25232 KB |
Time limit exceeded |
9 |
Execution timed out |
5037 ms |
33676 KB |
Time limit exceeded |
10 |
Execution timed out |
5051 ms |
35460 KB |
Time limit exceeded |