#include <bits/stdc++.h>
#pragma GCC optimize("O3")
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
using namespace std;
vector<int>pos;
int arr[400100];
struct pq
{
int* q;
int r;
void init(vector<int>v)
{
q = (int*)calloc(v.size()+2, sizeof(int));
int i;
for (i = 0; i < v.size(); i++)
q[i + 1] = v[i];
r = v.size();
}
inline int up(int n)
{
if (q[1] <= n)
{
return n;
}
int rv = q[1];
int i = 1;
T:
if (i * 2 > r)
{
q[i] = n;
return rv;
}
if (q[i * 2] <= q[i * 2 + 1])
{
if (q[i * 2 + 1] <= n)
{
q[i] = n;
return rv;
}
q[i] = q[i * 2 + 1];
i = i * 2 + 1;
}
else
{
if (q[i * 2] <= n)
{
q[i] = n;
return rv;
}
q[i] = q[i * 2];
i = i * 2;
}
goto T;
}
};
pq poss[50100];
int q[25100][3];
int main()
{
int N, M;
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cin >> N >> M;
int i;
for (i = 0; i < N; i++)
{
cin >> arr[i];
}
for (i = 0; i < M; i++)
{
int a, b, c;
cin >> a >> b >> c;
a--;
b--;
q[i][0] = a;
q[i][1] = b;
q[i][2] = c;
pos.push_back(a);
pos.push_back(b + 1);
}
pos.push_back(0);
pos.push_back(N);
sort(pos.begin(), pos.end());
pos.erase(unique(pos.begin(), pos.end()), pos.end());
for (i = 0; i < pos.size() - 1; i++)
{
vector<int>x;
int j;
for (j = pos[i]; j < pos[i + 1]; j++)
{
x.push_back(arr[j]);
}
sort(x.begin(), x.end());
reverse(x.begin(), x.end());
poss[i].init(x);
}
int lm = pos.size() - 1;
for (i = 0; i < M; i++)
{
int a = lower_bound(pos.begin(), pos.end(), q[i][0]) - pos.begin();
int b = lower_bound(pos.begin(), pos.end(), q[i][1] + 1) - pos.begin();
int j;
int c = q[i][2];
if (q[i][0] > q[i][1])
{
for (j = a; j < lm; j++)
{
c = poss[j].up(c);
}
for (j = 0; j < b; j++)
{
c = poss[j].up(c);
}
}
else
{
for (j = a; j < b; j++)
{
c = poss[j].up(c);
}
}
cout << c << '\n';
}
}
Compilation message
sushi.cpp: In member function 'void pq::init(std::vector<int>)':
sushi.cpp:16:17: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
16 | for (i = 0; i < v.size(); i++)
| ~~^~~~~~~~~~
sushi.cpp: In function 'int main()':
sushi.cpp:87:16: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
87 | for (i = 0; i < pos.size() - 1; i++)
| ~~^~~~~~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
4 ms |
468 KB |
Output is correct |
2 |
Correct |
4 ms |
468 KB |
Output is correct |
3 |
Correct |
4 ms |
468 KB |
Output is correct |
4 |
Correct |
4 ms |
468 KB |
Output is correct |
5 |
Correct |
4 ms |
468 KB |
Output is correct |
6 |
Correct |
4 ms |
468 KB |
Output is correct |
7 |
Correct |
3 ms |
468 KB |
Output is correct |
8 |
Correct |
4 ms |
468 KB |
Output is correct |
9 |
Correct |
4 ms |
468 KB |
Output is correct |
10 |
Correct |
5 ms |
468 KB |
Output is correct |
11 |
Correct |
7 ms |
468 KB |
Output is correct |
12 |
Correct |
7 ms |
492 KB |
Output is correct |
13 |
Correct |
9 ms |
468 KB |
Output is correct |
14 |
Correct |
5 ms |
460 KB |
Output is correct |
15 |
Correct |
6 ms |
408 KB |
Output is correct |
16 |
Correct |
2 ms |
468 KB |
Output is correct |
17 |
Correct |
0 ms |
212 KB |
Output is correct |
18 |
Correct |
0 ms |
212 KB |
Output is correct |
19 |
Correct |
0 ms |
212 KB |
Output is correct |
20 |
Correct |
0 ms |
212 KB |
Output is correct |
21 |
Correct |
0 ms |
212 KB |
Output is correct |
22 |
Correct |
0 ms |
212 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
82 ms |
7128 KB |
Output is correct |
2 |
Correct |
88 ms |
7148 KB |
Output is correct |
3 |
Correct |
37 ms |
7216 KB |
Output is correct |
4 |
Correct |
86 ms |
7148 KB |
Output is correct |
5 |
Correct |
53 ms |
7100 KB |
Output is correct |
6 |
Correct |
56 ms |
7104 KB |
Output is correct |
7 |
Correct |
55 ms |
7104 KB |
Output is correct |
8 |
Correct |
53 ms |
7164 KB |
Output is correct |
9 |
Correct |
32 ms |
7200 KB |
Output is correct |
10 |
Correct |
46 ms |
7092 KB |
Output is correct |
11 |
Correct |
31 ms |
7276 KB |
Output is correct |
12 |
Correct |
46 ms |
7172 KB |
Output is correct |
13 |
Correct |
75 ms |
7168 KB |
Output is correct |
14 |
Correct |
73 ms |
7100 KB |
Output is correct |
15 |
Correct |
35 ms |
7104 KB |
Output is correct |
16 |
Correct |
77 ms |
7192 KB |
Output is correct |
17 |
Correct |
53 ms |
7156 KB |
Output is correct |
18 |
Correct |
56 ms |
7168 KB |
Output is correct |
19 |
Correct |
56 ms |
7192 KB |
Output is correct |
20 |
Correct |
54 ms |
7152 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
4 ms |
468 KB |
Output is correct |
2 |
Correct |
4 ms |
468 KB |
Output is correct |
3 |
Correct |
4 ms |
468 KB |
Output is correct |
4 |
Correct |
4 ms |
468 KB |
Output is correct |
5 |
Correct |
4 ms |
468 KB |
Output is correct |
6 |
Correct |
4 ms |
468 KB |
Output is correct |
7 |
Correct |
3 ms |
468 KB |
Output is correct |
8 |
Correct |
4 ms |
468 KB |
Output is correct |
9 |
Correct |
4 ms |
468 KB |
Output is correct |
10 |
Correct |
5 ms |
468 KB |
Output is correct |
11 |
Correct |
7 ms |
468 KB |
Output is correct |
12 |
Correct |
7 ms |
492 KB |
Output is correct |
13 |
Correct |
9 ms |
468 KB |
Output is correct |
14 |
Correct |
5 ms |
460 KB |
Output is correct |
15 |
Correct |
6 ms |
408 KB |
Output is correct |
16 |
Correct |
2 ms |
468 KB |
Output is correct |
17 |
Correct |
0 ms |
212 KB |
Output is correct |
18 |
Correct |
0 ms |
212 KB |
Output is correct |
19 |
Correct |
0 ms |
212 KB |
Output is correct |
20 |
Correct |
0 ms |
212 KB |
Output is correct |
21 |
Correct |
0 ms |
212 KB |
Output is correct |
22 |
Correct |
0 ms |
212 KB |
Output is correct |
23 |
Correct |
82 ms |
7128 KB |
Output is correct |
24 |
Correct |
88 ms |
7148 KB |
Output is correct |
25 |
Correct |
37 ms |
7216 KB |
Output is correct |
26 |
Correct |
86 ms |
7148 KB |
Output is correct |
27 |
Correct |
53 ms |
7100 KB |
Output is correct |
28 |
Correct |
56 ms |
7104 KB |
Output is correct |
29 |
Correct |
55 ms |
7104 KB |
Output is correct |
30 |
Correct |
53 ms |
7164 KB |
Output is correct |
31 |
Correct |
32 ms |
7200 KB |
Output is correct |
32 |
Correct |
46 ms |
7092 KB |
Output is correct |
33 |
Correct |
31 ms |
7276 KB |
Output is correct |
34 |
Correct |
46 ms |
7172 KB |
Output is correct |
35 |
Correct |
75 ms |
7168 KB |
Output is correct |
36 |
Correct |
73 ms |
7100 KB |
Output is correct |
37 |
Correct |
35 ms |
7104 KB |
Output is correct |
38 |
Correct |
77 ms |
7192 KB |
Output is correct |
39 |
Correct |
53 ms |
7156 KB |
Output is correct |
40 |
Correct |
56 ms |
7168 KB |
Output is correct |
41 |
Correct |
56 ms |
7192 KB |
Output is correct |
42 |
Correct |
54 ms |
7152 KB |
Output is correct |
43 |
Correct |
842 ms |
6076 KB |
Output is correct |
44 |
Correct |
897 ms |
6080 KB |
Output is correct |
45 |
Correct |
864 ms |
5996 KB |
Output is correct |
46 |
Correct |
800 ms |
6176 KB |
Output is correct |
47 |
Correct |
848 ms |
6044 KB |
Output is correct |
48 |
Correct |
7561 ms |
6480 KB |
Output is correct |
49 |
Correct |
7608 ms |
6172 KB |
Output is correct |
50 |
Correct |
7593 ms |
6148 KB |
Output is correct |
51 |
Correct |
7899 ms |
6072 KB |
Output is correct |
52 |
Correct |
1338 ms |
5200 KB |
Output is correct |
53 |
Correct |
1855 ms |
6068 KB |
Output is correct |
54 |
Correct |
11423 ms |
6272 KB |
Output is correct |
55 |
Correct |
11169 ms |
6320 KB |
Output is correct |
56 |
Correct |
11167 ms |
6148 KB |
Output is correct |
57 |
Correct |
11237 ms |
10436 KB |
Output is correct |
58 |
Correct |
7147 ms |
9340 KB |
Output is correct |
59 |
Correct |
8087 ms |
9348 KB |
Output is correct |
60 |
Correct |
86 ms |
11324 KB |
Output is correct |
61 |
Correct |
90 ms |
11320 KB |
Output is correct |
62 |
Correct |
91 ms |
11332 KB |
Output is correct |
63 |
Correct |
93 ms |
11332 KB |
Output is correct |
64 |
Correct |
915 ms |
6928 KB |
Output is correct |
65 |
Correct |
82 ms |
10144 KB |
Output is correct |
66 |
Correct |
67 ms |
10180 KB |
Output is correct |
67 |
Correct |
3816 ms |
10332 KB |
Output is correct |
68 |
Correct |
9618 ms |
10492 KB |
Output is correct |
69 |
Correct |
9674 ms |
10572 KB |
Output is correct |
70 |
Correct |
9714 ms |
10484 KB |
Output is correct |