#define REP(i, n) for(int i = 0; i < n; i ++)
#define REPL(i,m, n) for(int i = m; i < n; i ++)
#define FOREACH(it, l) for (auto it = l.begin(); it != l.end(); it++)
#define SORT(arr) sort(arr.begin(), arr.end())
#define LSOne(S) ((S)&-(S))
#define M_PI 3.1415926535897932384
#define INF 999999999
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int, int> ii;
typedef vector<ii> vii;
typedef long long ll;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef double ld;
class SegmentTree {
public:
vi prop;
vi val;
int n;
SegmentTree(int n) {
this-> n = n;
val.assign(4*n, INF);
prop.assign(4*n,0);
}
int l(int p) {
return p*2;
}
int r(int p) {
return p*2+1;
}
void propagate(int p, int L, int R) {
if (prop[p] != 0) {
val[p] += prop[p];
if (L!=R) {
int m = (L+R)/2;
prop[l(p)] += prop[p];
prop[r(p)] += prop[p];
}
prop[p]= 0;
}
}
int RMQ(int p, int L , int R, int i, int j) {
propagate(p, L, R);
if (R< i || L > j ) return INF;
if (L >= i && R <= j) return val[p];
int m = (L+R)/2;
return min(RMQ(l(p), L, m, i, j), RMQ(r(p), m+1, R, i, j));
}
void pointupdate(int p, int L, int R, int x, int newval) {
propagate(p, L,R);
if (R<x|| L>x ) return;
if (L== x && R== x) {
val[p] = newval;
return;
}
int m = (L+R)/2;
pointupdate(l(p), L, m,x, newval);
pointupdate(r(p), m+1, R, x, newval);
val[p] = min(val[r(p)], val[l(p)]);
}
};
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL); cout.tie(NULL);
int n,m;
cin>>n>>m;
vi arr = {n*m};
REP(i, n) {
int x;cin>>x;
x += (n-i-1)*m;
arr.push_back(x);
}
set<int> allval;
for (auto x:arr) {
allval.insert(x);
}
map<int,int> comp;
int idx =0;
for (auto x: allval) {
comp[x] = idx++;
}
vi farr;
for (auto x: arr) {
farr.push_back(comp[x]);
}
SegmentTree tr(idx);
tr.pointupdate(1, 0, idx-1, farr[0], 0);
REPL(i,1, n+1) {
int bstval = tr.RMQ(1,0,idx-1,farr[i], idx-1);
tr.prop[1]++;
tr.pointupdate(1,0,idx-1,farr[i], bstval);
}
cout<<tr.RMQ(1,0,idx-1,0,idx-1);
}
Compilation message
triusis.cpp: In member function 'void SegmentTree::propagate(int, int, int)':
triusis.cpp:41:9: warning: unused variable 'm' [-Wunused-variable]
41 | int m = (L+R)/2;
| ^
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
204 KB |
Output is correct |
2 |
Correct |
1 ms |
204 KB |
Output is correct |
3 |
Correct |
0 ms |
312 KB |
Output is correct |
4 |
Correct |
1 ms |
204 KB |
Output is correct |
5 |
Correct |
1 ms |
312 KB |
Output is correct |
6 |
Correct |
0 ms |
204 KB |
Output is correct |
7 |
Correct |
0 ms |
204 KB |
Output is correct |
8 |
Correct |
1 ms |
312 KB |
Output is correct |
9 |
Correct |
0 ms |
204 KB |
Output is correct |
10 |
Correct |
0 ms |
204 KB |
Output is correct |
11 |
Correct |
0 ms |
204 KB |
Output is correct |
12 |
Correct |
0 ms |
204 KB |
Output is correct |
13 |
Correct |
0 ms |
204 KB |
Output is correct |
14 |
Correct |
0 ms |
312 KB |
Output is correct |
15 |
Correct |
1 ms |
204 KB |
Output is correct |
16 |
Correct |
0 ms |
312 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
204 KB |
Output is correct |
2 |
Correct |
1 ms |
204 KB |
Output is correct |
3 |
Correct |
0 ms |
312 KB |
Output is correct |
4 |
Correct |
1 ms |
204 KB |
Output is correct |
5 |
Correct |
1 ms |
312 KB |
Output is correct |
6 |
Correct |
0 ms |
204 KB |
Output is correct |
7 |
Correct |
0 ms |
204 KB |
Output is correct |
8 |
Correct |
1 ms |
312 KB |
Output is correct |
9 |
Correct |
0 ms |
204 KB |
Output is correct |
10 |
Correct |
0 ms |
204 KB |
Output is correct |
11 |
Correct |
0 ms |
204 KB |
Output is correct |
12 |
Correct |
0 ms |
204 KB |
Output is correct |
13 |
Correct |
0 ms |
204 KB |
Output is correct |
14 |
Correct |
0 ms |
312 KB |
Output is correct |
15 |
Correct |
1 ms |
204 KB |
Output is correct |
16 |
Correct |
0 ms |
312 KB |
Output is correct |
17 |
Correct |
0 ms |
296 KB |
Output is correct |
18 |
Correct |
0 ms |
308 KB |
Output is correct |
19 |
Correct |
0 ms |
204 KB |
Output is correct |
20 |
Correct |
3 ms |
844 KB |
Output is correct |
21 |
Correct |
3 ms |
972 KB |
Output is correct |
22 |
Correct |
4 ms |
712 KB |
Output is correct |
23 |
Correct |
4 ms |
972 KB |
Output is correct |
24 |
Correct |
3 ms |
972 KB |
Output is correct |
25 |
Correct |
4 ms |
972 KB |
Output is correct |
26 |
Correct |
4 ms |
992 KB |
Output is correct |
27 |
Correct |
1 ms |
324 KB |
Output is correct |
28 |
Correct |
1 ms |
324 KB |
Output is correct |
29 |
Correct |
5 ms |
972 KB |
Output is correct |
30 |
Correct |
5 ms |
972 KB |
Output is correct |
31 |
Correct |
3 ms |
716 KB |
Output is correct |
32 |
Correct |
6 ms |
972 KB |
Output is correct |
33 |
Correct |
5 ms |
968 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
296 KB |
Output is correct |
2 |
Correct |
0 ms |
308 KB |
Output is correct |
3 |
Correct |
0 ms |
204 KB |
Output is correct |
4 |
Correct |
3 ms |
844 KB |
Output is correct |
5 |
Correct |
3 ms |
972 KB |
Output is correct |
6 |
Correct |
4 ms |
712 KB |
Output is correct |
7 |
Correct |
4 ms |
972 KB |
Output is correct |
8 |
Correct |
3 ms |
972 KB |
Output is correct |
9 |
Correct |
4 ms |
972 KB |
Output is correct |
10 |
Correct |
4 ms |
992 KB |
Output is correct |
11 |
Correct |
1 ms |
324 KB |
Output is correct |
12 |
Correct |
1 ms |
324 KB |
Output is correct |
13 |
Correct |
5 ms |
972 KB |
Output is correct |
14 |
Correct |
5 ms |
972 KB |
Output is correct |
15 |
Correct |
3 ms |
716 KB |
Output is correct |
16 |
Correct |
6 ms |
972 KB |
Output is correct |
17 |
Correct |
5 ms |
968 KB |
Output is correct |
18 |
Correct |
0 ms |
204 KB |
Output is correct |
19 |
Correct |
1 ms |
204 KB |
Output is correct |
20 |
Correct |
0 ms |
312 KB |
Output is correct |
21 |
Correct |
1 ms |
204 KB |
Output is correct |
22 |
Correct |
1 ms |
312 KB |
Output is correct |
23 |
Correct |
0 ms |
204 KB |
Output is correct |
24 |
Correct |
0 ms |
204 KB |
Output is correct |
25 |
Correct |
1 ms |
312 KB |
Output is correct |
26 |
Correct |
0 ms |
204 KB |
Output is correct |
27 |
Correct |
0 ms |
204 KB |
Output is correct |
28 |
Correct |
0 ms |
204 KB |
Output is correct |
29 |
Correct |
0 ms |
204 KB |
Output is correct |
30 |
Correct |
0 ms |
204 KB |
Output is correct |
31 |
Correct |
0 ms |
312 KB |
Output is correct |
32 |
Correct |
1 ms |
204 KB |
Output is correct |
33 |
Correct |
0 ms |
312 KB |
Output is correct |
34 |
Correct |
4 ms |
1036 KB |
Output is correct |
35 |
Correct |
5 ms |
1000 KB |
Output is correct |
36 |
Correct |
4 ms |
964 KB |
Output is correct |
37 |
Correct |
5 ms |
960 KB |
Output is correct |
38 |
Correct |
1 ms |
368 KB |
Output is correct |
39 |
Correct |
1 ms |
352 KB |
Output is correct |
40 |
Correct |
3 ms |
716 KB |
Output is correct |
41 |
Correct |
1 ms |
332 KB |
Output is correct |
42 |
Correct |
4 ms |
972 KB |
Output is correct |
43 |
Correct |
4 ms |
972 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
1036 KB |
Output is correct |
2 |
Correct |
5 ms |
1000 KB |
Output is correct |
3 |
Correct |
4 ms |
964 KB |
Output is correct |
4 |
Correct |
5 ms |
960 KB |
Output is correct |
5 |
Correct |
1 ms |
368 KB |
Output is correct |
6 |
Correct |
1 ms |
352 KB |
Output is correct |
7 |
Correct |
3 ms |
716 KB |
Output is correct |
8 |
Correct |
1 ms |
332 KB |
Output is correct |
9 |
Correct |
4 ms |
972 KB |
Output is correct |
10 |
Correct |
4 ms |
972 KB |
Output is correct |
11 |
Correct |
0 ms |
296 KB |
Output is correct |
12 |
Correct |
0 ms |
308 KB |
Output is correct |
13 |
Correct |
0 ms |
204 KB |
Output is correct |
14 |
Correct |
3 ms |
844 KB |
Output is correct |
15 |
Correct |
3 ms |
972 KB |
Output is correct |
16 |
Correct |
4 ms |
712 KB |
Output is correct |
17 |
Correct |
4 ms |
972 KB |
Output is correct |
18 |
Correct |
3 ms |
972 KB |
Output is correct |
19 |
Correct |
4 ms |
972 KB |
Output is correct |
20 |
Correct |
4 ms |
992 KB |
Output is correct |
21 |
Correct |
1 ms |
324 KB |
Output is correct |
22 |
Correct |
1 ms |
324 KB |
Output is correct |
23 |
Correct |
5 ms |
972 KB |
Output is correct |
24 |
Correct |
5 ms |
972 KB |
Output is correct |
25 |
Correct |
3 ms |
716 KB |
Output is correct |
26 |
Correct |
6 ms |
972 KB |
Output is correct |
27 |
Correct |
5 ms |
968 KB |
Output is correct |
28 |
Correct |
0 ms |
204 KB |
Output is correct |
29 |
Correct |
1 ms |
204 KB |
Output is correct |
30 |
Correct |
0 ms |
312 KB |
Output is correct |
31 |
Correct |
1 ms |
204 KB |
Output is correct |
32 |
Correct |
1 ms |
312 KB |
Output is correct |
33 |
Correct |
0 ms |
204 KB |
Output is correct |
34 |
Correct |
0 ms |
204 KB |
Output is correct |
35 |
Correct |
1 ms |
312 KB |
Output is correct |
36 |
Correct |
0 ms |
204 KB |
Output is correct |
37 |
Correct |
0 ms |
204 KB |
Output is correct |
38 |
Correct |
0 ms |
204 KB |
Output is correct |
39 |
Correct |
0 ms |
204 KB |
Output is correct |
40 |
Correct |
0 ms |
204 KB |
Output is correct |
41 |
Correct |
0 ms |
312 KB |
Output is correct |
42 |
Correct |
1 ms |
204 KB |
Output is correct |
43 |
Correct |
0 ms |
312 KB |
Output is correct |
44 |
Correct |
180 ms |
27572 KB |
Output is correct |
45 |
Correct |
322 ms |
28944 KB |
Output is correct |
46 |
Correct |
318 ms |
29088 KB |
Output is correct |
47 |
Correct |
330 ms |
29000 KB |
Output is correct |
48 |
Correct |
193 ms |
27484 KB |
Output is correct |
49 |
Correct |
181 ms |
28088 KB |
Output is correct |
50 |
Correct |
40 ms |
4436 KB |
Output is correct |
51 |
Correct |
29 ms |
4492 KB |
Output is correct |
52 |
Correct |
145 ms |
15420 KB |
Output is correct |
53 |
Correct |
21 ms |
3776 KB |
Output is correct |
54 |
Correct |
188 ms |
27852 KB |
Output is correct |
55 |
Correct |
188 ms |
27724 KB |
Output is correct |