# |
제출 시각 |
아이디 |
문제 |
언어 |
결과 |
실행 시간 |
메모리 |
1027512 |
2024-07-19T07:11:33 Z |
정희우(#10953) |
Sushi (JOI16_sushi) |
C++17 |
|
364 ms |
262144 KB |
#include<iostream>
#include<algorithm>
#include<vector>
#include<set>
using namespace std;
using lint = long long;
using intp = pair<int,int>;
using vint = vector<int>;
const int MAX_N=400010;
struct Seg
{
multiset<int> val;
multiset<int> lazy;
int push(int v)
{
if(val.empty()) while(1);
auto it=prev(val.end());
if(*it<=v)
return v;
int v2=*it;
val.erase(it);
if(it==val.end()) while(1);
val.insert(v);
lazy.insert(v);
if(lazy.size()>val.size())
{
if(lazy.empty()) while(1);
auto del=prev(lazy.end());
if(del==lazy.end()) while(1);
lazy.erase(del);
}
return v2;
}
};
int n,q;
int initv[MAX_N];
Seg seg[MAX_N<<2];
void init_(int i,int s,int e)
{
for(int j=s;j<e;j++)
seg[i].val.insert(initv[j]);
if(s+1==e)
return;
init_(i<<1,s,(s+e)>>1);
init_(i<<1|1,(s+e)>>1,e);
}
void update_lazy(Seg &p,Seg &l,Seg &r)
{
for(auto v : p.lazy)
{
int v2=l.push(v);
r.push(v2);
}
p.lazy.clear();
}
int update_(int i,int s,int e,int l,int r,int v)
{
if(s>=r || e<=l)
return v;
if(l<=s && e<=r)
{
int v2=seg[i].push(v);
return v2;
}
update_lazy(seg[i],seg[i<<1],seg[i<<1|1]);
int v1=update_(i<<1,s,(s+e)>>1,l,r,v);
int v2=update_(i<<1|1,(s+e)>>1,e,l,r,v1);
if(v!=v2)
{
auto del=seg[i].val.find(v2);
if(del==seg[i].val.end()) while(1);
seg[i].val.erase(del);
seg[i].val.insert(v);
}
return v2;
}
int main()
{
ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);
cin >> n >> q;
for(int i=0;i<n;i++)
cin >> initv[i];
init_(1,0,n);
while(q--)
{
int s,t,p;
cin >> s >> t >> p;
if(s<=t)
p=update_(1,0,n,s-1,t,p);
else
{
p=update_(1,0,n,s-1,n,p);
p=update_(1,0,n,0,t,p);
}
cout << p << '\n';
}
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
46 ms |
151888 KB |
Output is correct |
2 |
Correct |
42 ms |
151944 KB |
Output is correct |
3 |
Correct |
50 ms |
151888 KB |
Output is correct |
4 |
Correct |
48 ms |
151896 KB |
Output is correct |
5 |
Correct |
47 ms |
151892 KB |
Output is correct |
6 |
Correct |
46 ms |
151896 KB |
Output is correct |
7 |
Correct |
47 ms |
151888 KB |
Output is correct |
8 |
Correct |
48 ms |
151892 KB |
Output is correct |
9 |
Correct |
50 ms |
151972 KB |
Output is correct |
10 |
Correct |
46 ms |
151836 KB |
Output is correct |
11 |
Correct |
70 ms |
151892 KB |
Output is correct |
12 |
Correct |
65 ms |
151892 KB |
Output is correct |
13 |
Correct |
70 ms |
151888 KB |
Output is correct |
14 |
Correct |
54 ms |
151888 KB |
Output is correct |
15 |
Correct |
52 ms |
151900 KB |
Output is correct |
16 |
Correct |
43 ms |
151896 KB |
Output is correct |
17 |
Correct |
36 ms |
150616 KB |
Output is correct |
18 |
Correct |
43 ms |
150612 KB |
Output is correct |
19 |
Correct |
36 ms |
150612 KB |
Output is correct |
20 |
Correct |
37 ms |
150620 KB |
Output is correct |
21 |
Correct |
36 ms |
150712 KB |
Output is correct |
22 |
Correct |
39 ms |
150540 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
364 ms |
262144 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
46 ms |
151888 KB |
Output is correct |
2 |
Correct |
42 ms |
151944 KB |
Output is correct |
3 |
Correct |
50 ms |
151888 KB |
Output is correct |
4 |
Correct |
48 ms |
151896 KB |
Output is correct |
5 |
Correct |
47 ms |
151892 KB |
Output is correct |
6 |
Correct |
46 ms |
151896 KB |
Output is correct |
7 |
Correct |
47 ms |
151888 KB |
Output is correct |
8 |
Correct |
48 ms |
151892 KB |
Output is correct |
9 |
Correct |
50 ms |
151972 KB |
Output is correct |
10 |
Correct |
46 ms |
151836 KB |
Output is correct |
11 |
Correct |
70 ms |
151892 KB |
Output is correct |
12 |
Correct |
65 ms |
151892 KB |
Output is correct |
13 |
Correct |
70 ms |
151888 KB |
Output is correct |
14 |
Correct |
54 ms |
151888 KB |
Output is correct |
15 |
Correct |
52 ms |
151900 KB |
Output is correct |
16 |
Correct |
43 ms |
151896 KB |
Output is correct |
17 |
Correct |
36 ms |
150616 KB |
Output is correct |
18 |
Correct |
43 ms |
150612 KB |
Output is correct |
19 |
Correct |
36 ms |
150612 KB |
Output is correct |
20 |
Correct |
37 ms |
150620 KB |
Output is correct |
21 |
Correct |
36 ms |
150712 KB |
Output is correct |
22 |
Correct |
39 ms |
150540 KB |
Output is correct |
23 |
Runtime error |
364 ms |
262144 KB |
Execution killed with signal 9 |
24 |
Halted |
0 ms |
0 KB |
- |