#include <bits/stdc++.h>
using namespace std;
#define int long long
#define maxn 100050
#define sqrtn 320
#define f first
#define s second
vector<int> seg(maxn*4,0);
vector<int> num(maxn,0);
vector<int> compress;
vector<int> vect1;
vector<int> ans(maxn,0);
vector<vector<pair<int,pair<int,int> > > > queries(sqrtn);
priority_queue<int> ins,del;
void insert(int node){
//cout << node << endl;
num[node] += compress[node];
ins.push(num[node]);
}
void deleter(int node){
//cout << node << endl;
del.push(num[node]);
num[node] -= compress[node];
}
int32_t main() {
ios::sync_with_stdio(0);
cin.tie(0);cout.tie(0);
int n,m;
int input;
cin >> n >> m;
for(int i=0;i<n;i++){
cin >> input;
compress.push_back(input);
vect1.push_back(input);
}
sort(compress.begin(),compress.end());
for(int i=0;i<n;i++){
vect1[i] = lower_bound(compress.begin(),compress.end(),vect1[i])-compress.begin();
}
int a,b;
for(int i=0;i<m;i++){
cin >> a >> b;
a--,b--;
queries[a/sqrtn].push_back({b,{a,i}});
}
//cout << "YES" << endl;
int l = 0,r = -1;
for(int i=0;i<sqrtn;i++){
sort(queries[i].begin(),queries[i].end());
for(auto k:queries[i]){
while(l>k.s.f){
l--;
insert(vect1[l]);
}
while(l<k.s.f){
deleter(vect1[l]);
l++;
}
while(r<k.f){
r++;
insert(vect1[r]);
}
while(r>k.f){
deleter(vect1[r]);
r--;
}
while(del.size()>0&&ins.top()==del.top()){
ins.pop();
del.pop();
}
ans[k.s.s] = ins.top();
// cout << "YES" << endl;
}
}
for(int i=0;i<m;i++){
cout << ans[i] << "\n";
}
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
4940 KB |
Output is correct |
2 |
Correct |
3 ms |
4940 KB |
Output is correct |
3 |
Correct |
4 ms |
4940 KB |
Output is correct |
4 |
Correct |
4 ms |
5044 KB |
Output is correct |
5 |
Correct |
3 ms |
4940 KB |
Output is correct |
6 |
Correct |
3 ms |
4940 KB |
Output is correct |
7 |
Correct |
4 ms |
4940 KB |
Output is correct |
8 |
Correct |
4 ms |
4940 KB |
Output is correct |
9 |
Correct |
5 ms |
4940 KB |
Output is correct |
10 |
Correct |
3 ms |
4940 KB |
Output is correct |
11 |
Correct |
4 ms |
4940 KB |
Output is correct |
12 |
Correct |
3 ms |
4940 KB |
Output is correct |
13 |
Correct |
4 ms |
4940 KB |
Output is correct |
14 |
Correct |
3 ms |
4940 KB |
Output is correct |
15 |
Correct |
3 ms |
4940 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
4940 KB |
Output is correct |
2 |
Correct |
3 ms |
4940 KB |
Output is correct |
3 |
Correct |
4 ms |
4940 KB |
Output is correct |
4 |
Correct |
4 ms |
5044 KB |
Output is correct |
5 |
Correct |
3 ms |
4940 KB |
Output is correct |
6 |
Correct |
3 ms |
4940 KB |
Output is correct |
7 |
Correct |
4 ms |
4940 KB |
Output is correct |
8 |
Correct |
4 ms |
4940 KB |
Output is correct |
9 |
Correct |
5 ms |
4940 KB |
Output is correct |
10 |
Correct |
3 ms |
4940 KB |
Output is correct |
11 |
Correct |
4 ms |
4940 KB |
Output is correct |
12 |
Correct |
3 ms |
4940 KB |
Output is correct |
13 |
Correct |
4 ms |
4940 KB |
Output is correct |
14 |
Correct |
3 ms |
4940 KB |
Output is correct |
15 |
Correct |
3 ms |
4940 KB |
Output is correct |
16 |
Correct |
4 ms |
5068 KB |
Output is correct |
17 |
Correct |
7 ms |
5196 KB |
Output is correct |
18 |
Correct |
12 ms |
5580 KB |
Output is correct |
19 |
Correct |
23 ms |
5676 KB |
Output is correct |
20 |
Correct |
53 ms |
6184 KB |
Output is correct |
21 |
Correct |
87 ms |
6132 KB |
Output is correct |
22 |
Correct |
82 ms |
6184 KB |
Output is correct |
23 |
Correct |
106 ms |
6184 KB |
Output is correct |
24 |
Correct |
85 ms |
6176 KB |
Output is correct |
25 |
Correct |
67 ms |
7424 KB |
Output is correct |
26 |
Correct |
87 ms |
8464 KB |
Output is correct |
27 |
Correct |
76 ms |
7028 KB |
Output is correct |
28 |
Correct |
75 ms |
7544 KB |
Output is correct |
29 |
Correct |
74 ms |
7216 KB |
Output is correct |
30 |
Correct |
77 ms |
7100 KB |
Output is correct |
31 |
Correct |
89 ms |
6176 KB |
Output is correct |
32 |
Correct |
78 ms |
5960 KB |
Output is correct |
33 |
Correct |
74 ms |
7228 KB |
Output is correct |
34 |
Correct |
87 ms |
8536 KB |
Output is correct |
35 |
Correct |
70 ms |
8464 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
4940 KB |
Output is correct |
2 |
Correct |
4 ms |
5004 KB |
Output is correct |
3 |
Correct |
3 ms |
4940 KB |
Output is correct |
4 |
Correct |
3 ms |
5068 KB |
Output is correct |
5 |
Correct |
4 ms |
5068 KB |
Output is correct |
6 |
Correct |
5 ms |
5060 KB |
Output is correct |
7 |
Correct |
7 ms |
5292 KB |
Output is correct |
8 |
Correct |
8 ms |
5580 KB |
Output is correct |
9 |
Correct |
13 ms |
5960 KB |
Output is correct |
10 |
Correct |
21 ms |
5960 KB |
Output is correct |
11 |
Correct |
76 ms |
11004 KB |
Output is correct |
12 |
Correct |
51 ms |
8096 KB |
Output is correct |
13 |
Correct |
74 ms |
9884 KB |
Output is correct |
14 |
Correct |
90 ms |
10528 KB |
Output is correct |
15 |
Correct |
91 ms |
11680 KB |
Output is correct |
16 |
Correct |
76 ms |
10672 KB |
Output is correct |
17 |
Correct |
45 ms |
9264 KB |
Output is correct |
18 |
Correct |
63 ms |
11824 KB |
Output is correct |
19 |
Correct |
63 ms |
12188 KB |
Output is correct |
20 |
Correct |
45 ms |
8852 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
4940 KB |
Output is correct |
2 |
Correct |
3 ms |
4940 KB |
Output is correct |
3 |
Correct |
4 ms |
4940 KB |
Output is correct |
4 |
Correct |
4 ms |
5044 KB |
Output is correct |
5 |
Correct |
3 ms |
4940 KB |
Output is correct |
6 |
Correct |
3 ms |
4940 KB |
Output is correct |
7 |
Correct |
4 ms |
4940 KB |
Output is correct |
8 |
Correct |
4 ms |
4940 KB |
Output is correct |
9 |
Correct |
5 ms |
4940 KB |
Output is correct |
10 |
Correct |
3 ms |
4940 KB |
Output is correct |
11 |
Correct |
4 ms |
4940 KB |
Output is correct |
12 |
Correct |
3 ms |
4940 KB |
Output is correct |
13 |
Correct |
4 ms |
4940 KB |
Output is correct |
14 |
Correct |
3 ms |
4940 KB |
Output is correct |
15 |
Correct |
3 ms |
4940 KB |
Output is correct |
16 |
Correct |
4 ms |
5068 KB |
Output is correct |
17 |
Correct |
7 ms |
5196 KB |
Output is correct |
18 |
Correct |
12 ms |
5580 KB |
Output is correct |
19 |
Correct |
23 ms |
5676 KB |
Output is correct |
20 |
Correct |
53 ms |
6184 KB |
Output is correct |
21 |
Correct |
87 ms |
6132 KB |
Output is correct |
22 |
Correct |
82 ms |
6184 KB |
Output is correct |
23 |
Correct |
106 ms |
6184 KB |
Output is correct |
24 |
Correct |
85 ms |
6176 KB |
Output is correct |
25 |
Correct |
67 ms |
7424 KB |
Output is correct |
26 |
Correct |
87 ms |
8464 KB |
Output is correct |
27 |
Correct |
76 ms |
7028 KB |
Output is correct |
28 |
Correct |
75 ms |
7544 KB |
Output is correct |
29 |
Correct |
74 ms |
7216 KB |
Output is correct |
30 |
Correct |
77 ms |
7100 KB |
Output is correct |
31 |
Correct |
89 ms |
6176 KB |
Output is correct |
32 |
Correct |
78 ms |
5960 KB |
Output is correct |
33 |
Correct |
74 ms |
7228 KB |
Output is correct |
34 |
Correct |
87 ms |
8536 KB |
Output is correct |
35 |
Correct |
70 ms |
8464 KB |
Output is correct |
36 |
Correct |
4 ms |
4940 KB |
Output is correct |
37 |
Correct |
4 ms |
5004 KB |
Output is correct |
38 |
Correct |
3 ms |
4940 KB |
Output is correct |
39 |
Correct |
3 ms |
5068 KB |
Output is correct |
40 |
Correct |
4 ms |
5068 KB |
Output is correct |
41 |
Correct |
5 ms |
5060 KB |
Output is correct |
42 |
Correct |
7 ms |
5292 KB |
Output is correct |
43 |
Correct |
8 ms |
5580 KB |
Output is correct |
44 |
Correct |
13 ms |
5960 KB |
Output is correct |
45 |
Correct |
21 ms |
5960 KB |
Output is correct |
46 |
Correct |
76 ms |
11004 KB |
Output is correct |
47 |
Correct |
51 ms |
8096 KB |
Output is correct |
48 |
Correct |
74 ms |
9884 KB |
Output is correct |
49 |
Correct |
90 ms |
10528 KB |
Output is correct |
50 |
Correct |
91 ms |
11680 KB |
Output is correct |
51 |
Correct |
76 ms |
10672 KB |
Output is correct |
52 |
Correct |
45 ms |
9264 KB |
Output is correct |
53 |
Correct |
63 ms |
11824 KB |
Output is correct |
54 |
Correct |
63 ms |
12188 KB |
Output is correct |
55 |
Correct |
45 ms |
8852 KB |
Output is correct |
56 |
Correct |
198 ms |
6564 KB |
Output is correct |
57 |
Correct |
585 ms |
9308 KB |
Output is correct |
58 |
Correct |
872 ms |
20196 KB |
Output is correct |
59 |
Correct |
1733 ms |
35920 KB |
Output is correct |
60 |
Correct |
2120 ms |
57076 KB |
Output is correct |
61 |
Correct |
2886 ms |
34648 KB |
Output is correct |
62 |
Correct |
3708 ms |
15928 KB |
Output is correct |
63 |
Execution timed out |
4091 ms |
14008 KB |
Time limit exceeded |
64 |
Halted |
0 ms |
0 KB |
- |