Submission #912328

# Submission time Handle Problem Language Result Execution time Memory
912328 2024-01-19T10:02:47 Z vjudge1 Rabbit Carrot (LMIO19_triusis) C++17
100 / 100
487 ms 31708 KB
// #pragma GCC target( "sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
// #pragma GCC optimize("Ofast,unroll-loops,fast-math,O3")  
#include<bits/stdc++.h>
#define f first
#define s second
#define pb push_back
#define sz(x) (int)x.size()
#define bit(a, i) ((a>>i)&1)

using namespace std;
typedef long long ll;
typedef pair<int, int> pii;

const int P = 18;
const int K = 800;
const ll INF = 2e18;
const int inf = 1e9;
const int mod = 1e9+7;
const int maxm = 5e2+10;
const int maxn = 2e5+10;
const int dx[] = {0, 0, -1, 1};
const int dy[] = {1, -1, 0, 0};

ll a[maxn];
ll b[maxn];
int n, m, sz;
int dp[maxn];
int d[4*maxn];
int t[4*maxn];
map<ll, int>cnt;

void push(int v=1, int tl=1, int tr=sz){
    t[v<<1] += d[v];
    t[v<<1|1] += d[v];
    d[v<<1] += d[v];
    d[v<<1|1] += d[v];
    d[v] = 0;
}

void build(int v=1, int tl=1, int tr=sz){
    if(tl == tr) t[v] = inf;
    else{
        int tm = tl+tr>>1;
        build(v<<1, tl, tm);
        build(v<<1|1, tm+1, tr);
        t[v] = min(t[v<<1], t[v<<1|1]);
    }
}

int get(int l, int v=1, int tl=1, int tr=sz){
    if(l > tr) return inf;
    if(l <= tl) return t[v];
    push(v);
    int tm = tl+tr>>1;
    return min(get(l, v<<1, tl, tm), get(l, v<<1|1, tm+1, tr)); 
}

void upd(int i, int x, int v=1, int tl=1, int tr=sz){
    if(tl == tr) t[v] = min(t[v], x);
    else{
        push(v);
        int tm = tl+tr>>1;
        if(i <= tm) upd(i, x, v<<1, tl, tm);
        else upd(i, x, v<<1|1, tm+1, tr);
        t[v] = min(t[v<<1], t[v<<1|1]);
    }
}

int main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
    cin >> n >> m;
    int ans = n;
    set<ll>st;
    st.insert(0);
    for(int i=1; i<=n; i++){
        cin >> a[i];
        b[i] = a[i]-i*1ll*m;
        st.insert(b[i]);
    } for(auto to: st) cnt[to] = ++sz; 
    build();
    upd(cnt[0], 0);
    for(int i=1; i<=n; i++){
        dp[i] = min(inf, get(cnt[b[i]]));
        t[1]++; d[1]++;
        upd(cnt[b[i]], dp[i]);
        ans = min(ans, dp[i]+n-i);
    }
    cout << ans;
}

Compilation message

triusis.cpp: In function 'void build(int, int, int)':
triusis.cpp:43:20: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   43 |         int tm = tl+tr>>1;
      |                  ~~^~~
triusis.cpp: In function 'int get(int, int, int, int)':
triusis.cpp:54:16: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   54 |     int tm = tl+tr>>1;
      |              ~~^~~
triusis.cpp: In function 'void upd(int, int, int, int, int)':
triusis.cpp:62:20: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   62 |         int tm = tl+tr>>1;
      |                  ~~^~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 6492 KB Output is correct
2 Correct 1 ms 4444 KB Output is correct
3 Correct 1 ms 4444 KB Output is correct
4 Correct 1 ms 4444 KB Output is correct
5 Correct 1 ms 4444 KB Output is correct
6 Correct 1 ms 4444 KB Output is correct
7 Correct 2 ms 4440 KB Output is correct
8 Correct 1 ms 4444 KB Output is correct
9 Correct 1 ms 4444 KB Output is correct
10 Correct 1 ms 4440 KB Output is correct
11 Correct 1 ms 4444 KB Output is correct
12 Correct 1 ms 4444 KB Output is correct
13 Correct 1 ms 4444 KB Output is correct
14 Correct 1 ms 4444 KB Output is correct
15 Correct 1 ms 4444 KB Output is correct
16 Correct 1 ms 4440 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 6492 KB Output is correct
2 Correct 1 ms 4444 KB Output is correct
3 Correct 1 ms 4444 KB Output is correct
4 Correct 1 ms 4444 KB Output is correct
5 Correct 1 ms 4444 KB Output is correct
6 Correct 1 ms 4444 KB Output is correct
7 Correct 2 ms 4440 KB Output is correct
8 Correct 1 ms 4444 KB Output is correct
9 Correct 1 ms 4444 KB Output is correct
10 Correct 1 ms 4440 KB Output is correct
11 Correct 1 ms 4444 KB Output is correct
12 Correct 1 ms 4444 KB Output is correct
13 Correct 1 ms 4444 KB Output is correct
14 Correct 1 ms 4444 KB Output is correct
15 Correct 1 ms 4444 KB Output is correct
16 Correct 1 ms 4440 KB Output is correct
17 Correct 1 ms 4440 KB Output is correct
18 Correct 1 ms 4440 KB Output is correct
19 Correct 1 ms 4444 KB Output is correct
20 Correct 4 ms 4956 KB Output is correct
21 Correct 5 ms 5212 KB Output is correct
22 Correct 4 ms 4956 KB Output is correct
23 Correct 4 ms 5212 KB Output is correct
24 Correct 4 ms 5212 KB Output is correct
25 Correct 4 ms 5212 KB Output is correct
26 Correct 7 ms 5212 KB Output is correct
27 Correct 2 ms 4440 KB Output is correct
28 Correct 2 ms 4440 KB Output is correct
29 Correct 5 ms 5212 KB Output is correct
30 Correct 5 ms 5272 KB Output is correct
31 Correct 3 ms 4956 KB Output is correct
32 Correct 4 ms 5212 KB Output is correct
33 Correct 4 ms 5208 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 4440 KB Output is correct
2 Correct 1 ms 4440 KB Output is correct
3 Correct 1 ms 4444 KB Output is correct
4 Correct 4 ms 4956 KB Output is correct
5 Correct 5 ms 5212 KB Output is correct
6 Correct 4 ms 4956 KB Output is correct
7 Correct 4 ms 5212 KB Output is correct
8 Correct 4 ms 5212 KB Output is correct
9 Correct 4 ms 5212 KB Output is correct
10 Correct 7 ms 5212 KB Output is correct
11 Correct 2 ms 4440 KB Output is correct
12 Correct 2 ms 4440 KB Output is correct
13 Correct 5 ms 5212 KB Output is correct
14 Correct 5 ms 5272 KB Output is correct
15 Correct 3 ms 4956 KB Output is correct
16 Correct 4 ms 5212 KB Output is correct
17 Correct 4 ms 5208 KB Output is correct
18 Correct 1 ms 6492 KB Output is correct
19 Correct 1 ms 4444 KB Output is correct
20 Correct 1 ms 4444 KB Output is correct
21 Correct 1 ms 4444 KB Output is correct
22 Correct 1 ms 4444 KB Output is correct
23 Correct 1 ms 4444 KB Output is correct
24 Correct 2 ms 4440 KB Output is correct
25 Correct 1 ms 4444 KB Output is correct
26 Correct 1 ms 4444 KB Output is correct
27 Correct 1 ms 4440 KB Output is correct
28 Correct 1 ms 4444 KB Output is correct
29 Correct 1 ms 4444 KB Output is correct
30 Correct 1 ms 4444 KB Output is correct
31 Correct 1 ms 4444 KB Output is correct
32 Correct 1 ms 4444 KB Output is correct
33 Correct 1 ms 4440 KB Output is correct
34 Correct 5 ms 5212 KB Output is correct
35 Correct 6 ms 5212 KB Output is correct
36 Correct 6 ms 5212 KB Output is correct
37 Correct 7 ms 5212 KB Output is correct
38 Correct 2 ms 4596 KB Output is correct
39 Correct 2 ms 4444 KB Output is correct
40 Correct 3 ms 4952 KB Output is correct
41 Correct 2 ms 4444 KB Output is correct
42 Correct 4 ms 5212 KB Output is correct
43 Correct 4 ms 5212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 5212 KB Output is correct
2 Correct 6 ms 5212 KB Output is correct
3 Correct 6 ms 5212 KB Output is correct
4 Correct 7 ms 5212 KB Output is correct
5 Correct 2 ms 4596 KB Output is correct
6 Correct 2 ms 4444 KB Output is correct
7 Correct 3 ms 4952 KB Output is correct
8 Correct 2 ms 4444 KB Output is correct
9 Correct 4 ms 5212 KB Output is correct
10 Correct 4 ms 5212 KB Output is correct
11 Correct 1 ms 4440 KB Output is correct
12 Correct 1 ms 4440 KB Output is correct
13 Correct 1 ms 4444 KB Output is correct
14 Correct 4 ms 4956 KB Output is correct
15 Correct 5 ms 5212 KB Output is correct
16 Correct 4 ms 4956 KB Output is correct
17 Correct 4 ms 5212 KB Output is correct
18 Correct 4 ms 5212 KB Output is correct
19 Correct 4 ms 5212 KB Output is correct
20 Correct 7 ms 5212 KB Output is correct
21 Correct 2 ms 4440 KB Output is correct
22 Correct 2 ms 4440 KB Output is correct
23 Correct 5 ms 5212 KB Output is correct
24 Correct 5 ms 5272 KB Output is correct
25 Correct 3 ms 4956 KB Output is correct
26 Correct 4 ms 5212 KB Output is correct
27 Correct 4 ms 5208 KB Output is correct
28 Correct 1 ms 6492 KB Output is correct
29 Correct 1 ms 4444 KB Output is correct
30 Correct 1 ms 4444 KB Output is correct
31 Correct 1 ms 4444 KB Output is correct
32 Correct 1 ms 4444 KB Output is correct
33 Correct 1 ms 4444 KB Output is correct
34 Correct 2 ms 4440 KB Output is correct
35 Correct 1 ms 4444 KB Output is correct
36 Correct 1 ms 4444 KB Output is correct
37 Correct 1 ms 4440 KB Output is correct
38 Correct 1 ms 4444 KB Output is correct
39 Correct 1 ms 4444 KB Output is correct
40 Correct 1 ms 4444 KB Output is correct
41 Correct 1 ms 4444 KB Output is correct
42 Correct 1 ms 4444 KB Output is correct
43 Correct 1 ms 4440 KB Output is correct
44 Correct 193 ms 31524 KB Output is correct
45 Correct 487 ms 31624 KB Output is correct
46 Correct 396 ms 31708 KB Output is correct
47 Correct 398 ms 31620 KB Output is correct
48 Correct 176 ms 30840 KB Output is correct
49 Correct 179 ms 31596 KB Output is correct
50 Correct 26 ms 6208 KB Output is correct
51 Correct 26 ms 6348 KB Output is correct
52 Correct 155 ms 20544 KB Output is correct
53 Correct 18 ms 6236 KB Output is correct
54 Correct 205 ms 31388 KB Output is correct
55 Correct 181 ms 31120 KB Output is correct