MCPcopy Create free account
hub / github.com/Jonathan-Uy/CSES-Solutions / main

Function main

Dynamic Programming/Increasing Subsequence II.cpp:24–41  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

22}
23
24int main(){
25 scanf("%d", &N);
26 for(int i = 0, x; i < N; i++){
27 scanf("%d", &x);
28 ops[i] = {x, i+1};
29 }
30 sort(ops, ops+N, [](Operation A, Operation B){
31 return A.x == B.x ? B.idx < A.idx : A.x < B.x;
32 });
33
34 for(int i = 0; i < N; i++){
35 int idx = ops[i].idx;
36 ll amnt = query(idx)+1;
37 ans = (ans + amnt) % MOD;
38 update(idx, amnt);
39 }
40 printf("%lld\n", ans);
41}

Callers

nothing calls this directly

Calls 2

queryFunction · 0.70
updateFunction · 0.70

Tested by

no test coverage detected