Submission #50617234
Source Code Expand
#include<bits/stdc++.h>
using namespace std;
const int maxn = 2e5 + 10;
int a[maxn];
namespace segment
{
set<pair<int,int>> st[maxn << 2];
#define ls p << 1
#define rs p << 1 | 1
void build(int p,int l,int r)
{
if(l == r)
{
cin >> a[l];
st[p].insert({a[l],-1});
return ;
}
int mid = l + r >> 1;
build(ls,l,mid);
build(rs,mid + 1,r);
}
void update(int p,int l,int r,int L,int R,pair<int,int> k)
{
if(L <= l && r <= R)
{
st[p].insert(k);
return ;
}
int mid = l + r >> 1;
if(L <= mid)
{
update(ls,l,mid,L,R,k);
}
if(R > mid)
{
update(rs,mid + 1,r,L,R,k);
}
}
void delet(int p,int l,int r,int L,int R,pair<int,int> k)
{
if(L <= l && r <= R)
{
st[p].erase(k);
return ;
}
int mid = l + r >> 1;
if(L <= mid)
{
delet(ls,l,mid,L,R,k);
}
if(R > mid)
{
delet(rs,mid + 1,r,L,R,k);
}
}
int query(int p,int l,int r,int k)
{
int ans = st[p].empty() ? 0 : (*st[p].rbegin()).first;
if(l == r)
{
return ans;
}
int mid = l + r >> 1;
if(k <= mid)
{
ans = max(ans,query(ls,l,mid,k));
}
else
{
ans = max(ans,query(rs,mid + 1,r,k));
}
return ans;
}
}using namespace segment;
int n,q;
int L[maxn],R[maxn],val[maxn];
int main()
{
cin >> n;
build(1,1,n);
cin >> q;
for(int i = 1;i <= q;i++)
{
int opt;
cin >> opt;
if(opt == 1)
{
cin >> L[i] >> R[i] >> val[i];
update(1,1,n,L[i],R[i],make_pair(val[i],i));
}
else if(opt == 2)
{
int id;
cin >> id;
delet(1,1,n,L[id],R[id],make_pair(val[id],id));
}
else
{
int id;
cin >> id;
cout << query(1,1,n,id) << '\n';
}
}
return 0;
}
Submission Info
Compile Error
Main.cpp: In function ‘void segment::build(int, int, int)’:
Main.cpp:18:21: warning: suggest parentheses around ‘+’ inside ‘>>’ [-Wparentheses]
18 | int mid = l + r >> 1;
| ~~^~~
Main.cpp: In function ‘void segment::update(int, int, int, int, int, std::pair<int, int>)’:
Main.cpp:29:21: warning: suggest parentheses around ‘+’ inside ‘>>’ [-Wparentheses]
29 | int mid = l + r >> 1;
| ~~^~~
Main.cpp: In function ‘void segment::delet(int, int, int, int, int, std::pair<int, int>)’:
Main.cpp:46:21: warning: suggest parentheses around ‘+’ inside ‘>>’ [-Wparentheses]
46 | int mid = l + r >> 1;
| ~~^~~
Main.cpp: In function ‘int segment::query(int, int, int, int)’:
Main.cpp:63:21: warning: suggest parentheses around ‘+’ inside ‘>>’ [-Wparentheses]
63 | int mid = l + r >> 1;
| ~~^~~
Judge Result
Set Name |
Sample |
All |
Score / Max Score |
0 / 0 |
625 / 625 |
Status |
|
|
Set Name |
Test Cases |
Sample |
00_sample_00.txt, 00_sample_01.txt |
All |
00_sample_00.txt, 00_sample_01.txt, 01_random_02.txt, 01_random_03.txt, 01_random_04.txt, 01_random_05.txt, 01_random_06.txt, 01_random_07.txt, 01_random_08.txt, 01_random_09.txt, 01_random_10.txt, 01_random_11.txt, 01_random_12.txt, 01_random_13.txt, 01_random_14.txt, 01_random_15.txt, 01_random_16.txt, 01_random_17.txt, 01_random_18.txt, 01_random_19.txt, 01_random_20.txt, 01_random_21.txt, 01_random_22.txt, 01_random_23.txt, 01_random_24.txt, 01_random_25.txt, 01_random_26.txt, 01_random_27.txt, 01_random_28.txt, 01_random_29.txt, 01_random_30.txt, 01_random_31.txt, 01_random_32.txt, 01_random_33.txt, 01_random_34.txt, 02_handmade_35.txt, 02_handmade_36.txt, 02_handmade_37.txt, 02_handmade_38.txt, 02_handmade_39.txt, 02_handmade_40.txt, 02_handmade_41.txt, 02_handmade_42.txt, 02_handmade_43.txt |
Case Name |
Status |
Exec Time |
Memory |
00_sample_00.txt |
AC |
18 ms |
40964 KiB |
00_sample_01.txt |
AC |
17 ms |
41028 KiB |
01_random_02.txt |
AC |
406 ms |
53976 KiB |
01_random_03.txt |
AC |
401 ms |
53840 KiB |
01_random_04.txt |
AC |
75 ms |
45136 KiB |
01_random_05.txt |
AC |
402 ms |
53616 KiB |
01_random_06.txt |
AC |
401 ms |
53556 KiB |
01_random_07.txt |
AC |
247 ms |
49856 KiB |
01_random_08.txt |
AC |
337 ms |
53460 KiB |
01_random_09.txt |
AC |
338 ms |
53480 KiB |
01_random_10.txt |
AC |
104 ms |
42488 KiB |
01_random_11.txt |
AC |
2221 ms |
196272 KiB |
01_random_12.txt |
AC |
2223 ms |
196316 KiB |
01_random_13.txt |
AC |
674 ms |
101172 KiB |
01_random_14.txt |
AC |
395 ms |
54052 KiB |
01_random_15.txt |
AC |
358 ms |
53652 KiB |
01_random_16.txt |
AC |
193 ms |
46480 KiB |
01_random_17.txt |
AC |
1156 ms |
125528 KiB |
01_random_18.txt |
AC |
1172 ms |
126132 KiB |
01_random_19.txt |
AC |
919 ms |
110152 KiB |
01_random_20.txt |
AC |
398 ms |
53436 KiB |
01_random_21.txt |
AC |
397 ms |
53480 KiB |
01_random_22.txt |
AC |
56 ms |
41924 KiB |
01_random_23.txt |
AC |
359 ms |
53892 KiB |
01_random_24.txt |
AC |
394 ms |
53876 KiB |
01_random_25.txt |
AC |
148 ms |
46216 KiB |
01_random_26.txt |
AC |
1166 ms |
126592 KiB |
01_random_27.txt |
AC |
1163 ms |
127008 KiB |
01_random_28.txt |
AC |
960 ms |
113016 KiB |
01_random_29.txt |
AC |
2250 ms |
200540 KiB |
01_random_30.txt |
AC |
2253 ms |
200644 KiB |
01_random_31.txt |
AC |
813 ms |
115040 KiB |
01_random_32.txt |
AC |
399 ms |
51172 KiB |
01_random_33.txt |
AC |
398 ms |
51124 KiB |
01_random_34.txt |
AC |
183 ms |
47136 KiB |
02_handmade_35.txt |
AC |
909 ms |
131672 KiB |
02_handmade_36.txt |
AC |
290 ms |
58124 KiB |
02_handmade_37.txt |
AC |
116 ms |
55196 KiB |
02_handmade_38.txt |
AC |
116 ms |
55052 KiB |
02_handmade_39.txt |
AC |
150 ms |
57056 KiB |
02_handmade_40.txt |
AC |
152 ms |
57056 KiB |
02_handmade_41.txt |
AC |
202 ms |
62844 KiB |
02_handmade_42.txt |
AC |
951 ms |
131704 KiB |
02_handmade_43.txt |
AC |
18 ms |
41040 KiB |