# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
1109147 |
2024-11-06T06:05:16 Z |
azberjibiou |
Sushi (JOI16_sushi) |
C++17 |
|
2271 ms |
6868 KB |
#include <bits/stdc++.h>
#define all(v) v.begin(), v.end()
#define pb push_back
#define lb lower_bound
#define gibon ios::sync_with_stdio(false); cin.tie(0);
#define fi first
#define se second
#define pii pair<int, int>
#define pll pair<ll, ll>
typedef long long ll;
using namespace std;
const int mxN=400400;
const int mxQ=25050;
const int MOD=998244353;
const ll INF=1e18;
const int B=400;
int N, Q;
int A[mxN];
int s[mxQ], e[mxQ], h[mxQ];
int ans[mxQ];
priority_queue <int> pqA[2*B+5], pqH[2*B+5];
void input(){
cin >> N >> Q;
for(int i=1;i<=N;i++) cin >> A[i];
for(int i=1;i<=Q;i++) cin >> s[i] >> e[i] >> h[i];
}
void add(int idx, int &nh){
int maxi=pqA[idx].top();
if(maxi<=nh) return;
pqA[idx].pop();
pqA[idx].push(nh);
pqH[idx].push(-nh);
nh=maxi;
}
void solv(int l, int r){
vector <int> cr;
cr.push_back(1); cr.push_back(N+1);
for(int i=l;i<=r;i++) cr.push_back(s[i]), cr.push_back(e[i]+1);
sort(all(cr));
cr.erase(unique(all(cr)), cr.end());
for(int i=0;i<cr.size()-1;i++){
for(int j=cr[i];j<cr[i+1];j++) pqA[i].push(A[j]);
}
for(int i=l;i<=r;i++){
int ns=s[i], ne=e[i]+1;
ns=lower_bound(all(cr), ns)-cr.begin();
ne=lower_bound(all(cr), ne)-cr.begin();
if(ns<ne){
int nh=h[i];
for(int j=ns;j<ne;j++) add(j, nh);
ans[i]=nh;
}
else{
int nh=h[i];
for(int j=ns;j+1<cr.size();j++) add(j, nh);
for(int j=0;j<ne;j++) add(j, nh);
ans[i]=nh;
}
}
for(int i=0;i+1<cr.size();i++){
for(int j=cr[i];j<cr[i+1];j++){
if(pqH[i].empty()) break;
int mini=-pqH[i].top();
if(mini>=A[j]) continue;
pqH[i].pop();
pqH[i].push(-A[j]);
A[j]=mini;
}
}
for(int i=0;i<cr.size();i++) pqH[i]=priority_queue<int>(), pqA[i]=priority_queue<int>();
}
int main(){
gibon
input();
for(int i=1;i<=Q;i+=B){
solv(i, min(i+B-1, Q));
}
for(int i=1;i<=Q;i++) cout << ans[i] << '\n';
}
Compilation message
sushi.cpp: In function 'void solv(int, int)':
sushi.cpp:41:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
41 | for(int i=0;i<cr.size()-1;i++){
| ~^~~~~~~~~~~~
sushi.cpp:55:29: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
55 | for(int j=ns;j+1<cr.size();j++) add(j, nh);
| ~~~^~~~~~~~~~
sushi.cpp:60:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
60 | for(int i=0;i+1<cr.size();i++){
| ~~~^~~~~~~~~~
sushi.cpp:71:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
71 | for(int i=0;i<cr.size();i++) pqH[i]=priority_queue<int>(), pqA[i]=priority_queue<int>();
| ~^~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
9 ms |
592 KB |
Output is correct |
2 |
Correct |
9 ms |
592 KB |
Output is correct |
3 |
Correct |
9 ms |
592 KB |
Output is correct |
4 |
Correct |
6 ms |
592 KB |
Output is correct |
5 |
Correct |
6 ms |
616 KB |
Output is correct |
6 |
Correct |
6 ms |
632 KB |
Output is correct |
7 |
Correct |
5 ms |
592 KB |
Output is correct |
8 |
Correct |
4 ms |
592 KB |
Output is correct |
9 |
Correct |
6 ms |
656 KB |
Output is correct |
10 |
Correct |
6 ms |
592 KB |
Output is correct |
11 |
Correct |
12 ms |
1104 KB |
Output is correct |
12 |
Correct |
12 ms |
1120 KB |
Output is correct |
13 |
Correct |
21 ms |
848 KB |
Output is correct |
14 |
Correct |
7 ms |
604 KB |
Output is correct |
15 |
Correct |
10 ms |
592 KB |
Output is correct |
16 |
Correct |
3 ms |
612 KB |
Output is correct |
17 |
Correct |
1 ms |
336 KB |
Output is correct |
18 |
Correct |
1 ms |
336 KB |
Output is correct |
19 |
Correct |
1 ms |
336 KB |
Output is correct |
20 |
Correct |
1 ms |
336 KB |
Output is correct |
21 |
Correct |
1 ms |
336 KB |
Output is correct |
22 |
Correct |
1 ms |
336 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
786 ms |
6080 KB |
Output is correct |
2 |
Correct |
751 ms |
6088 KB |
Output is correct |
3 |
Correct |
420 ms |
6140 KB |
Output is correct |
4 |
Correct |
780 ms |
6084 KB |
Output is correct |
5 |
Correct |
1773 ms |
6184 KB |
Output is correct |
6 |
Correct |
2244 ms |
6080 KB |
Output is correct |
7 |
Correct |
2229 ms |
6076 KB |
Output is correct |
8 |
Correct |
2102 ms |
6076 KB |
Output is correct |
9 |
Correct |
304 ms |
6132 KB |
Output is correct |
10 |
Correct |
1942 ms |
6068 KB |
Output is correct |
11 |
Correct |
263 ms |
6136 KB |
Output is correct |
12 |
Correct |
1883 ms |
6092 KB |
Output is correct |
13 |
Correct |
798 ms |
6080 KB |
Output is correct |
14 |
Correct |
804 ms |
6084 KB |
Output is correct |
15 |
Correct |
461 ms |
6116 KB |
Output is correct |
16 |
Correct |
752 ms |
6096 KB |
Output is correct |
17 |
Correct |
1667 ms |
6080 KB |
Output is correct |
18 |
Correct |
2149 ms |
6056 KB |
Output is correct |
19 |
Correct |
2080 ms |
6072 KB |
Output is correct |
20 |
Correct |
2118 ms |
6076 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
9 ms |
592 KB |
Output is correct |
2 |
Correct |
9 ms |
592 KB |
Output is correct |
3 |
Correct |
9 ms |
592 KB |
Output is correct |
4 |
Correct |
6 ms |
592 KB |
Output is correct |
5 |
Correct |
6 ms |
616 KB |
Output is correct |
6 |
Correct |
6 ms |
632 KB |
Output is correct |
7 |
Correct |
5 ms |
592 KB |
Output is correct |
8 |
Correct |
4 ms |
592 KB |
Output is correct |
9 |
Correct |
6 ms |
656 KB |
Output is correct |
10 |
Correct |
6 ms |
592 KB |
Output is correct |
11 |
Correct |
12 ms |
1104 KB |
Output is correct |
12 |
Correct |
12 ms |
1120 KB |
Output is correct |
13 |
Correct |
21 ms |
848 KB |
Output is correct |
14 |
Correct |
7 ms |
604 KB |
Output is correct |
15 |
Correct |
10 ms |
592 KB |
Output is correct |
16 |
Correct |
3 ms |
612 KB |
Output is correct |
17 |
Correct |
1 ms |
336 KB |
Output is correct |
18 |
Correct |
1 ms |
336 KB |
Output is correct |
19 |
Correct |
1 ms |
336 KB |
Output is correct |
20 |
Correct |
1 ms |
336 KB |
Output is correct |
21 |
Correct |
1 ms |
336 KB |
Output is correct |
22 |
Correct |
1 ms |
336 KB |
Output is correct |
23 |
Correct |
786 ms |
6080 KB |
Output is correct |
24 |
Correct |
751 ms |
6088 KB |
Output is correct |
25 |
Correct |
420 ms |
6140 KB |
Output is correct |
26 |
Correct |
780 ms |
6084 KB |
Output is correct |
27 |
Correct |
1773 ms |
6184 KB |
Output is correct |
28 |
Correct |
2244 ms |
6080 KB |
Output is correct |
29 |
Correct |
2229 ms |
6076 KB |
Output is correct |
30 |
Correct |
2102 ms |
6076 KB |
Output is correct |
31 |
Correct |
304 ms |
6132 KB |
Output is correct |
32 |
Correct |
1942 ms |
6068 KB |
Output is correct |
33 |
Correct |
263 ms |
6136 KB |
Output is correct |
34 |
Correct |
1883 ms |
6092 KB |
Output is correct |
35 |
Correct |
798 ms |
6080 KB |
Output is correct |
36 |
Correct |
804 ms |
6084 KB |
Output is correct |
37 |
Correct |
461 ms |
6116 KB |
Output is correct |
38 |
Correct |
752 ms |
6096 KB |
Output is correct |
39 |
Correct |
1667 ms |
6080 KB |
Output is correct |
40 |
Correct |
2149 ms |
6056 KB |
Output is correct |
41 |
Correct |
2080 ms |
6072 KB |
Output is correct |
42 |
Correct |
2118 ms |
6076 KB |
Output is correct |
43 |
Correct |
517 ms |
4936 KB |
Output is correct |
44 |
Correct |
502 ms |
4936 KB |
Output is correct |
45 |
Correct |
258 ms |
4688 KB |
Output is correct |
46 |
Correct |
516 ms |
4940 KB |
Output is correct |
47 |
Correct |
494 ms |
4936 KB |
Output is correct |
48 |
Correct |
1619 ms |
5460 KB |
Output is correct |
49 |
Correct |
1867 ms |
5484 KB |
Output is correct |
50 |
Correct |
1840 ms |
5456 KB |
Output is correct |
51 |
Correct |
1754 ms |
5452 KB |
Output is correct |
52 |
Correct |
540 ms |
5104 KB |
Output is correct |
53 |
Correct |
529 ms |
4912 KB |
Output is correct |
54 |
Correct |
1925 ms |
5908 KB |
Output is correct |
55 |
Correct |
2240 ms |
5788 KB |
Output is correct |
56 |
Correct |
2085 ms |
5776 KB |
Output is correct |
57 |
Correct |
2009 ms |
5756 KB |
Output is correct |
58 |
Correct |
1623 ms |
5340 KB |
Output is correct |
59 |
Correct |
1720 ms |
5316 KB |
Output is correct |
60 |
Correct |
1981 ms |
6260 KB |
Output is correct |
61 |
Correct |
2135 ms |
6224 KB |
Output is correct |
62 |
Correct |
2271 ms |
6236 KB |
Output is correct |
63 |
Correct |
2267 ms |
6276 KB |
Output is correct |
64 |
Correct |
163 ms |
4712 KB |
Output is correct |
65 |
Correct |
1858 ms |
6736 KB |
Output is correct |
66 |
Correct |
1752 ms |
6228 KB |
Output is correct |
67 |
Correct |
1405 ms |
6728 KB |
Output is correct |
68 |
Correct |
1719 ms |
6824 KB |
Output is correct |
69 |
Correct |
1701 ms |
6840 KB |
Output is correct |
70 |
Correct |
1631 ms |
6868 KB |
Output is correct |