# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
1109144 |
2024-11-06T06:04:31 Z |
azberjibiou |
Sushi (JOI16_sushi) |
C++17 |
|
2280 ms |
11216 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=500;
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 |
7 ms |
592 KB |
Output is correct |
2 |
Correct |
6 ms |
760 KB |
Output is correct |
3 |
Correct |
6 ms |
592 KB |
Output is correct |
4 |
Correct |
6 ms |
592 KB |
Output is correct |
5 |
Correct |
6 ms |
696 KB |
Output is correct |
6 |
Correct |
6 ms |
592 KB |
Output is correct |
7 |
Correct |
5 ms |
652 KB |
Output is correct |
8 |
Correct |
5 ms |
592 KB |
Output is correct |
9 |
Correct |
6 ms |
592 KB |
Output is correct |
10 |
Correct |
6 ms |
592 KB |
Output is correct |
11 |
Correct |
14 ms |
1144 KB |
Output is correct |
12 |
Correct |
15 ms |
1360 KB |
Output is correct |
13 |
Correct |
16 ms |
1184 KB |
Output is correct |
14 |
Correct |
6 ms |
592 KB |
Output is correct |
15 |
Correct |
9 ms |
548 KB |
Output is correct |
16 |
Correct |
2 ms |
592 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 |
640 ms |
10584 KB |
Output is correct |
2 |
Correct |
635 ms |
9120 KB |
Output is correct |
3 |
Correct |
337 ms |
7188 KB |
Output is correct |
4 |
Correct |
603 ms |
10508 KB |
Output is correct |
5 |
Correct |
1405 ms |
10464 KB |
Output is correct |
6 |
Correct |
1758 ms |
10464 KB |
Output is correct |
7 |
Correct |
1736 ms |
10712 KB |
Output is correct |
8 |
Correct |
1713 ms |
10468 KB |
Output is correct |
9 |
Correct |
238 ms |
7192 KB |
Output is correct |
10 |
Correct |
1415 ms |
9580 KB |
Output is correct |
11 |
Correct |
215 ms |
7192 KB |
Output is correct |
12 |
Correct |
1561 ms |
9204 KB |
Output is correct |
13 |
Correct |
594 ms |
10404 KB |
Output is correct |
14 |
Correct |
566 ms |
9692 KB |
Output is correct |
15 |
Correct |
329 ms |
7168 KB |
Output is correct |
16 |
Correct |
625 ms |
10484 KB |
Output is correct |
17 |
Correct |
1340 ms |
10472 KB |
Output is correct |
18 |
Correct |
1727 ms |
10480 KB |
Output is correct |
19 |
Correct |
1787 ms |
10472 KB |
Output is correct |
20 |
Correct |
1791 ms |
10468 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
7 ms |
592 KB |
Output is correct |
2 |
Correct |
6 ms |
760 KB |
Output is correct |
3 |
Correct |
6 ms |
592 KB |
Output is correct |
4 |
Correct |
6 ms |
592 KB |
Output is correct |
5 |
Correct |
6 ms |
696 KB |
Output is correct |
6 |
Correct |
6 ms |
592 KB |
Output is correct |
7 |
Correct |
5 ms |
652 KB |
Output is correct |
8 |
Correct |
5 ms |
592 KB |
Output is correct |
9 |
Correct |
6 ms |
592 KB |
Output is correct |
10 |
Correct |
6 ms |
592 KB |
Output is correct |
11 |
Correct |
14 ms |
1144 KB |
Output is correct |
12 |
Correct |
15 ms |
1360 KB |
Output is correct |
13 |
Correct |
16 ms |
1184 KB |
Output is correct |
14 |
Correct |
6 ms |
592 KB |
Output is correct |
15 |
Correct |
9 ms |
548 KB |
Output is correct |
16 |
Correct |
2 ms |
592 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 |
640 ms |
10584 KB |
Output is correct |
24 |
Correct |
635 ms |
9120 KB |
Output is correct |
25 |
Correct |
337 ms |
7188 KB |
Output is correct |
26 |
Correct |
603 ms |
10508 KB |
Output is correct |
27 |
Correct |
1405 ms |
10464 KB |
Output is correct |
28 |
Correct |
1758 ms |
10464 KB |
Output is correct |
29 |
Correct |
1736 ms |
10712 KB |
Output is correct |
30 |
Correct |
1713 ms |
10468 KB |
Output is correct |
31 |
Correct |
238 ms |
7192 KB |
Output is correct |
32 |
Correct |
1415 ms |
9580 KB |
Output is correct |
33 |
Correct |
215 ms |
7192 KB |
Output is correct |
34 |
Correct |
1561 ms |
9204 KB |
Output is correct |
35 |
Correct |
594 ms |
10404 KB |
Output is correct |
36 |
Correct |
566 ms |
9692 KB |
Output is correct |
37 |
Correct |
329 ms |
7168 KB |
Output is correct |
38 |
Correct |
625 ms |
10484 KB |
Output is correct |
39 |
Correct |
1340 ms |
10472 KB |
Output is correct |
40 |
Correct |
1727 ms |
10480 KB |
Output is correct |
41 |
Correct |
1787 ms |
10472 KB |
Output is correct |
42 |
Correct |
1791 ms |
10468 KB |
Output is correct |
43 |
Correct |
454 ms |
9536 KB |
Output is correct |
44 |
Correct |
438 ms |
9532 KB |
Output is correct |
45 |
Correct |
225 ms |
5900 KB |
Output is correct |
46 |
Correct |
454 ms |
9544 KB |
Output is correct |
47 |
Correct |
443 ms |
9588 KB |
Output is correct |
48 |
Correct |
1531 ms |
10320 KB |
Output is correct |
49 |
Correct |
1829 ms |
10632 KB |
Output is correct |
50 |
Correct |
1907 ms |
10312 KB |
Output is correct |
51 |
Correct |
1633 ms |
10304 KB |
Output is correct |
52 |
Correct |
453 ms |
9568 KB |
Output is correct |
53 |
Correct |
542 ms |
9320 KB |
Output is correct |
54 |
Correct |
1953 ms |
10692 KB |
Output is correct |
55 |
Correct |
2280 ms |
10800 KB |
Output is correct |
56 |
Correct |
2280 ms |
10668 KB |
Output is correct |
57 |
Correct |
2225 ms |
10672 KB |
Output is correct |
58 |
Correct |
1477 ms |
9908 KB |
Output is correct |
59 |
Correct |
1594 ms |
10084 KB |
Output is correct |
60 |
Correct |
1736 ms |
10704 KB |
Output is correct |
61 |
Correct |
2080 ms |
10704 KB |
Output is correct |
62 |
Correct |
1900 ms |
10700 KB |
Output is correct |
63 |
Correct |
2003 ms |
10708 KB |
Output is correct |
64 |
Correct |
167 ms |
5900 KB |
Output is correct |
65 |
Correct |
1471 ms |
9248 KB |
Output is correct |
66 |
Correct |
1480 ms |
9348 KB |
Output is correct |
67 |
Correct |
1279 ms |
11124 KB |
Output is correct |
68 |
Correct |
1691 ms |
11088 KB |
Output is correct |
69 |
Correct |
1750 ms |
11216 KB |
Output is correct |
70 |
Correct |
1681 ms |
11148 KB |
Output is correct |