Submission #434974

# Submission time Handle Problem Language Result Execution time Memory
434974 2021-06-22T16:42:36 Z nguot Global Warming (CEOI18_glo) C++14
100 / 100
75 ms 5356 KB
#include <bits/stdc++.h>
using namespace std;
#define in ({int x=0;int c=getchar(),n=0;for(;!isdigit(c);c=getchar()) n=(c=='-');for(;isdigit(c);c=getchar()) x=x*10+c-'0';n?-x:x;})
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
int rnd(int l,int r){return l+rng()%(r-l+1);}
#define fasty ios_base::sync_with_stdio(0),cin.tie(0)
#define fori(x,a,b) for (int x=a;x<=b;++x)
#define ford(x,a,b) for (int x=a;x>=b;x--)
#define forv(a,b) for(auto&a:b)
#define fi first
#define se second
#define pb push_back
#define ii pair<int,int>
#define mt make_tuple
#define mp make_pair
#define all(a) a.begin(),a.end()
#define reset(f, x) memset(f, x, sizeof(f))
#define getbit(x,i) ((x>>i)&1)
#define batbit(x,i) (x|(1ll<<i))
#define tatbit(x,i) (x&~(1<<i))
#define gg exit(0);

const int N = 2e5 + 10;
int n,x,a[N],lis[N];
main()
{
    //freopen("task.inp","r",stdin);
    fasty;
    cin>>n>>x;
    fori(i,1,n) cin>>a[i];
    vector<int> dp(n,INT_MAX);
    int res = 0;
    fori(i,1,n)
    {
        int j = lower_bound(all(dp),a[i]) - dp.begin();
        lis[i] = j+1;
        res = max(res,j+1);
        dp[j] = a[i];
    }
    dp = vector<int>(n,INT_MAX);
    // longest decreasing subsequence ending at i of reverse
	// = longest increasing subsequence starting at i
    ford(i,n,1)
    {
        int j = lower_bound(all(dp),-a[i]+x) - dp.begin();//gia su 1->i ta giam tat ca cac ptu di x;
        res = max(lis[i]+j,res);
        int pos = lower_bound(all(dp),-a[i]) - dp.begin();
        dp[pos] = -a[i];
    }
    cout<<res;
}

Compilation message

glo.cpp:25:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   25 | main()
      | ^~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 1 ms 324 KB Output is correct
5 Correct 1 ms 332 KB Output is correct
6 Correct 1 ms 324 KB Output is correct
7 Correct 1 ms 204 KB Output is correct
8 Correct 1 ms 204 KB Output is correct
9 Correct 1 ms 204 KB Output is correct
10 Correct 1 ms 204 KB Output is correct
11 Correct 1 ms 204 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 1 ms 324 KB Output is correct
5 Correct 1 ms 332 KB Output is correct
6 Correct 1 ms 324 KB Output is correct
7 Correct 1 ms 204 KB Output is correct
8 Correct 1 ms 204 KB Output is correct
9 Correct 1 ms 204 KB Output is correct
10 Correct 1 ms 204 KB Output is correct
11 Correct 1 ms 204 KB Output is correct
12 Correct 1 ms 204 KB Output is correct
13 Correct 1 ms 204 KB Output is correct
14 Correct 1 ms 204 KB Output is correct
15 Correct 1 ms 332 KB Output is correct
16 Correct 1 ms 204 KB Output is correct
17 Correct 1 ms 204 KB Output is correct
18 Correct 1 ms 332 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 1 ms 324 KB Output is correct
5 Correct 1 ms 332 KB Output is correct
6 Correct 1 ms 324 KB Output is correct
7 Correct 1 ms 204 KB Output is correct
8 Correct 1 ms 204 KB Output is correct
9 Correct 1 ms 204 KB Output is correct
10 Correct 1 ms 204 KB Output is correct
11 Correct 1 ms 204 KB Output is correct
12 Correct 1 ms 204 KB Output is correct
13 Correct 1 ms 204 KB Output is correct
14 Correct 1 ms 204 KB Output is correct
15 Correct 1 ms 332 KB Output is correct
16 Correct 1 ms 204 KB Output is correct
17 Correct 1 ms 204 KB Output is correct
18 Correct 1 ms 332 KB Output is correct
19 Correct 1 ms 332 KB Output is correct
20 Correct 1 ms 272 KB Output is correct
21 Correct 1 ms 332 KB Output is correct
22 Correct 1 ms 328 KB Output is correct
23 Correct 2 ms 332 KB Output is correct
24 Correct 1 ms 332 KB Output is correct
25 Correct 1 ms 324 KB Output is correct
26 Correct 1 ms 332 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 63 ms 3412 KB Output is correct
2 Correct 65 ms 5280 KB Output is correct
3 Correct 63 ms 5252 KB Output is correct
4 Correct 64 ms 5356 KB Output is correct
5 Correct 47 ms 4600 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 16 ms 1100 KB Output is correct
2 Correct 15 ms 1484 KB Output is correct
3 Correct 15 ms 1496 KB Output is correct
4 Correct 13 ms 1356 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 13 ms 1344 KB Output is correct
7 Correct 13 ms 1608 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 29 ms 1868 KB Output is correct
2 Correct 30 ms 2748 KB Output is correct
3 Correct 60 ms 5344 KB Output is correct
4 Correct 49 ms 4548 KB Output is correct
5 Correct 25 ms 2380 KB Output is correct
6 Correct 42 ms 4412 KB Output is correct
7 Correct 46 ms 5104 KB Output is correct
8 Correct 25 ms 2880 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 1 ms 324 KB Output is correct
5 Correct 1 ms 332 KB Output is correct
6 Correct 1 ms 324 KB Output is correct
7 Correct 1 ms 204 KB Output is correct
8 Correct 1 ms 204 KB Output is correct
9 Correct 1 ms 204 KB Output is correct
10 Correct 1 ms 204 KB Output is correct
11 Correct 1 ms 204 KB Output is correct
12 Correct 1 ms 204 KB Output is correct
13 Correct 1 ms 204 KB Output is correct
14 Correct 1 ms 204 KB Output is correct
15 Correct 1 ms 332 KB Output is correct
16 Correct 1 ms 204 KB Output is correct
17 Correct 1 ms 204 KB Output is correct
18 Correct 1 ms 332 KB Output is correct
19 Correct 1 ms 332 KB Output is correct
20 Correct 1 ms 272 KB Output is correct
21 Correct 1 ms 332 KB Output is correct
22 Correct 1 ms 328 KB Output is correct
23 Correct 2 ms 332 KB Output is correct
24 Correct 1 ms 332 KB Output is correct
25 Correct 1 ms 324 KB Output is correct
26 Correct 1 ms 332 KB Output is correct
27 Correct 63 ms 3412 KB Output is correct
28 Correct 65 ms 5280 KB Output is correct
29 Correct 63 ms 5252 KB Output is correct
30 Correct 64 ms 5356 KB Output is correct
31 Correct 47 ms 4600 KB Output is correct
32 Correct 16 ms 1100 KB Output is correct
33 Correct 15 ms 1484 KB Output is correct
34 Correct 15 ms 1496 KB Output is correct
35 Correct 13 ms 1356 KB Output is correct
36 Correct 1 ms 204 KB Output is correct
37 Correct 13 ms 1344 KB Output is correct
38 Correct 13 ms 1608 KB Output is correct
39 Correct 29 ms 1868 KB Output is correct
40 Correct 30 ms 2748 KB Output is correct
41 Correct 60 ms 5344 KB Output is correct
42 Correct 49 ms 4548 KB Output is correct
43 Correct 25 ms 2380 KB Output is correct
44 Correct 42 ms 4412 KB Output is correct
45 Correct 46 ms 5104 KB Output is correct
46 Correct 25 ms 2880 KB Output is correct
47 Correct 31 ms 2756 KB Output is correct
48 Correct 31 ms 2756 KB Output is correct
49 Correct 75 ms 5320 KB Output is correct
50 Correct 47 ms 4556 KB Output is correct
51 Correct 41 ms 3396 KB Output is correct
52 Correct 52 ms 4688 KB Output is correct
53 Correct 42 ms 4676 KB Output is correct
54 Correct 55 ms 5272 KB Output is correct
55 Correct 52 ms 5316 KB Output is correct