Submission #1074825

# Submission time Handle Problem Language Result Execution time Memory
1074825 2024-08-25T14:46:54 Z dosts Global Warming (CEOI18_glo) C++17
48 / 100
2000 ms 262144 KB
//Dost SEFEROĞLU
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define pii pair<int,int>
#define ff first
#define ss second
#define sp << " " <<    
#define all(cont) cont.begin(),cont.end()
#define vi vector<int>
const int MOD = 1e9+7,inf = 2e12;
const int N = 5001;
vi vv;

int idx(int x) {
    return upper_bound(all(vv),x)-vv.begin();
}

struct FT{
    int n;
    vi bit;

    FT(int nn) {
        n = nn;
        bit.assign(nn+1,0);
    }

    void put(int p,int v) {
        for (int i=p;i<=n;i+=i&-i) bit[i]=max(bit[i],v);
    } 

    int get(int p) {
        int ans = 0;
        for (int i=p;i>0;i-=i&-i) ans=max(ans,bit[i]);
        return ans;
    }
    void reset() {
        bit.assign(n+1,0);
    }
};

struct ST {
    vector<multiset<int,greater<int>>> t;

    ST(int nn) {
        t.resize(4*nn+1);
    }

    void insert(int node,int l,int r,int p,int v) {
        t[node].insert(v);
        if (l == r) return;
        int m = (l+r) >> 1;
        if (p<=m) insert(2*node,l,m,p,v);
        else insert(2*node+1,m+1,r,p,v);
    }
    void erase(int node,int l,int r,int p,int v) {
        t[node].erase(t[node].find(v));
        if (l == r) return;
        int m = (l+r) >> 1;
        if (p<=m) erase(2*node,l,m,p,v);
        else erase(2*node+1,m+1,r,p,v);   
    }
    int query(int node,int l,int r,int L,int R) {
        if (l > R || r < L) return 0;
        if (l >= L && r<=R) {
            if (t[node].empty()) return 0;
            return *t[node].begin();
        }
        int m = (l+r) >> 1;
        return max(query(2*node,l,m,L,R),query(2*node+1,m+1,r,L,R));
    }
};
void solve() { 
    int n,x;
    cin >> n >> x;
    //corollary: always decrease some prefix
    //corollary: if you decrease 1..i you MUST use i.
    vi a(n+1);
    for (int i=1;i<=n;i++) cin >> a[i];
    for (int i=1;i<=n;i++) {
        vv.push_back(a[i]);
        vv.push_back(a[i]-x);
    }
    sort(all(vv));
    vv.erase(unique(all(vv)),vv.end());
    int sz = vv.size();
    FT ft(sz);
    vi p(n+1),s(n+1);
    for (int i=1;i<=n;i++) {
        p[i] = ft.get(idx(a[i])-1)+1;
        ft.put(idx(a[i]),p[i]);
    }
    ft.reset();
    for (int i=n;i>=1;i--) {
        s[i] = ft.get(sz-idx(a[i]))+1;
        ft.put(sz-idx(a[i])+1,s[i]);
    }
    ft.reset();
    int ans = 0;
    ST st(sz);
    for (int i=1;i<=n;i++) st.insert(1,1,sz,idx(a[i]),s[i]);
    for (int i=1;i<=n;i++) {
        st.erase(1,1,sz,idx(a[i]),s[i]);
        ans = max(ans,p[i]+st.query(1,1,sz,idx(a[i]-x)+1,sz));
    }
    cout << ans << endl;
}
 
signed main() { 
    ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    #ifdef Dodi
        freopen("in.txt","r",stdin);
        freopen("out.txt","w",stdout);
    #endif
    int t = 1;
    //cin >> t; 
    while (t --> 0) solve();
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 1 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 1 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 1 ms 344 KB Output is correct
13 Correct 1 ms 344 KB Output is correct
14 Correct 0 ms 344 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 1 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 1 ms 344 KB Output is correct
13 Correct 1 ms 344 KB Output is correct
14 Correct 0 ms 344 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 3 ms 1368 KB Output is correct
20 Correct 3 ms 1372 KB Output is correct
21 Correct 3 ms 1372 KB Output is correct
22 Correct 3 ms 1116 KB Output is correct
23 Correct 3 ms 1144 KB Output is correct
24 Correct 2 ms 1112 KB Output is correct
25 Correct 2 ms 1116 KB Output is correct
26 Correct 2 ms 1116 KB Output is correct
# Verdict Execution time Memory Grader output
1 Execution timed out 2092 ms 222816 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 396 ms 63436 KB Output is correct
2 Correct 370 ms 63524 KB Output is correct
3 Correct 394 ms 63492 KB Output is correct
4 Correct 194 ms 51556 KB Output is correct
5 Correct 0 ms 456 KB Output is correct
6 Correct 125 ms 51664 KB Output is correct
7 Correct 243 ms 59996 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 983 ms 131116 KB Output is correct
2 Correct 983 ms 132088 KB Output is correct
3 Runtime error 1357 ms 262144 KB Execution killed with signal 9
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 1 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 1 ms 344 KB Output is correct
13 Correct 1 ms 344 KB Output is correct
14 Correct 0 ms 344 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 3 ms 1368 KB Output is correct
20 Correct 3 ms 1372 KB Output is correct
21 Correct 3 ms 1372 KB Output is correct
22 Correct 3 ms 1116 KB Output is correct
23 Correct 3 ms 1144 KB Output is correct
24 Correct 2 ms 1112 KB Output is correct
25 Correct 2 ms 1116 KB Output is correct
26 Correct 2 ms 1116 KB Output is correct
27 Execution timed out 2092 ms 222816 KB Time limit exceeded
28 Halted 0 ms 0 KB -