Submission #929083

# Submission time Handle Problem Language Result Execution time Memory
929083 2024-02-17T16:31:10 Z haru09 Global Warming (CEOI18_glo) C++17
100 / 100
120 ms 6472 KB
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define fi first
#define se second
#define task "code"

const int ar=2e5+5;
const ll mod=1e9+7;
int n,x;
int a[ar];
int l[ar],r[ar];
vector<int> v;
int pos(int val)
{
    return lower_bound(v.begin(),v.end(),val)-v.begin()+1;
}
int bit[ar];
void update(int u,int v)
{
    int id=u;
    while(id<=n)
    {
        bit[id]=max(bit[id],v);
        id+=id&(-id);
    }
}
int get(int p)
{
    int id=p;
    int ans=0;
    while(id>0)
    {
        ans=max(ans,bit[id]);
        id-=id&(-id);
    }
    return ans;
}
int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);cout.tie(0);
    if (fopen(task".inp","r"))
    {
        freopen(task".inp","r",stdin);
        freopen(task".out","w",stdout);
    }
    cin>>n>>x;
    for (int i=1;i<=n;i++)
    {
        cin>>a[i];
        v.push_back(a[i]);
    }
    sort(v.begin(),v.end());
    for (int i=1;i<=n;i++)
    {
        int p=pos(a[i]);
        int dp=get(p-1)+1;
        update(p,dp);
        l[i]=dp;
    }
    for (int i=1;i<=n;i++) bit[i]=0;
    for (int i=n;i>=1;i--)
    {
        int p=n-pos(a[i]-x+1)+1;
        r[i]=get(p);
        p=n-pos(a[i])+1;
        int dp=get(p-1)+1;
        update(p,dp);
    }
    int ans=0;
    for (int i=1;i<=n;i++) ans=max(ans,l[i]+r[i]);
    cout<<ans;

}

Compilation message

glo.cpp: In function 'int main()':
glo.cpp:45:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   45 |         freopen(task".inp","r",stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~
glo.cpp:46:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   46 |         freopen(task".out","w",stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2392 KB Output is correct
2 Correct 1 ms 2392 KB Output is correct
3 Correct 0 ms 2396 KB Output is correct
4 Correct 1 ms 2396 KB Output is correct
5 Correct 1 ms 2396 KB Output is correct
6 Correct 1 ms 2396 KB Output is correct
7 Correct 1 ms 2396 KB Output is correct
8 Correct 1 ms 2392 KB Output is correct
9 Correct 1 ms 2396 KB Output is correct
10 Correct 1 ms 2396 KB Output is correct
11 Correct 1 ms 2396 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2392 KB Output is correct
2 Correct 1 ms 2392 KB Output is correct
3 Correct 0 ms 2396 KB Output is correct
4 Correct 1 ms 2396 KB Output is correct
5 Correct 1 ms 2396 KB Output is correct
6 Correct 1 ms 2396 KB Output is correct
7 Correct 1 ms 2396 KB Output is correct
8 Correct 1 ms 2392 KB Output is correct
9 Correct 1 ms 2396 KB Output is correct
10 Correct 1 ms 2396 KB Output is correct
11 Correct 1 ms 2396 KB Output is correct
12 Correct 1 ms 2396 KB Output is correct
13 Correct 1 ms 2396 KB Output is correct
14 Correct 0 ms 2396 KB Output is correct
15 Correct 1 ms 2396 KB Output is correct
16 Correct 1 ms 2392 KB Output is correct
17 Correct 1 ms 2396 KB Output is correct
18 Correct 1 ms 2396 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2392 KB Output is correct
2 Correct 1 ms 2392 KB Output is correct
3 Correct 0 ms 2396 KB Output is correct
4 Correct 1 ms 2396 KB Output is correct
5 Correct 1 ms 2396 KB Output is correct
6 Correct 1 ms 2396 KB Output is correct
7 Correct 1 ms 2396 KB Output is correct
8 Correct 1 ms 2392 KB Output is correct
9 Correct 1 ms 2396 KB Output is correct
10 Correct 1 ms 2396 KB Output is correct
11 Correct 1 ms 2396 KB Output is correct
12 Correct 1 ms 2396 KB Output is correct
13 Correct 1 ms 2396 KB Output is correct
14 Correct 0 ms 2396 KB Output is correct
15 Correct 1 ms 2396 KB Output is correct
16 Correct 1 ms 2392 KB Output is correct
17 Correct 1 ms 2396 KB Output is correct
18 Correct 1 ms 2396 KB Output is correct
19 Correct 1 ms 2396 KB Output is correct
20 Correct 1 ms 2396 KB Output is correct
21 Correct 1 ms 2396 KB Output is correct
22 Correct 1 ms 2396 KB Output is correct
23 Correct 1 ms 2396 KB Output is correct
24 Correct 1 ms 2396 KB Output is correct
25 Correct 1 ms 2516 KB Output is correct
26 Correct 1 ms 2396 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 111 ms 6348 KB Output is correct
2 Correct 120 ms 6336 KB Output is correct
3 Correct 116 ms 6472 KB Output is correct
4 Correct 111 ms 6348 KB Output is correct
5 Correct 52 ms 5584 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 24 ms 3804 KB Output is correct
2 Correct 24 ms 3548 KB Output is correct
3 Correct 25 ms 3548 KB Output is correct
4 Correct 12 ms 3316 KB Output is correct
5 Correct 1 ms 2392 KB Output is correct
6 Correct 14 ms 3324 KB Output is correct
7 Correct 20 ms 3548 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 52 ms 4392 KB Output is correct
2 Correct 45 ms 4312 KB Output is correct
3 Correct 95 ms 6344 KB Output is correct
4 Correct 46 ms 5632 KB Output is correct
5 Correct 27 ms 4056 KB Output is correct
6 Correct 47 ms 5336 KB Output is correct
7 Correct 52 ms 6092 KB Output is correct
8 Correct 37 ms 4572 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2392 KB Output is correct
2 Correct 1 ms 2392 KB Output is correct
3 Correct 0 ms 2396 KB Output is correct
4 Correct 1 ms 2396 KB Output is correct
5 Correct 1 ms 2396 KB Output is correct
6 Correct 1 ms 2396 KB Output is correct
7 Correct 1 ms 2396 KB Output is correct
8 Correct 1 ms 2392 KB Output is correct
9 Correct 1 ms 2396 KB Output is correct
10 Correct 1 ms 2396 KB Output is correct
11 Correct 1 ms 2396 KB Output is correct
12 Correct 1 ms 2396 KB Output is correct
13 Correct 1 ms 2396 KB Output is correct
14 Correct 0 ms 2396 KB Output is correct
15 Correct 1 ms 2396 KB Output is correct
16 Correct 1 ms 2392 KB Output is correct
17 Correct 1 ms 2396 KB Output is correct
18 Correct 1 ms 2396 KB Output is correct
19 Correct 1 ms 2396 KB Output is correct
20 Correct 1 ms 2396 KB Output is correct
21 Correct 1 ms 2396 KB Output is correct
22 Correct 1 ms 2396 KB Output is correct
23 Correct 1 ms 2396 KB Output is correct
24 Correct 1 ms 2396 KB Output is correct
25 Correct 1 ms 2516 KB Output is correct
26 Correct 1 ms 2396 KB Output is correct
27 Correct 111 ms 6348 KB Output is correct
28 Correct 120 ms 6336 KB Output is correct
29 Correct 116 ms 6472 KB Output is correct
30 Correct 111 ms 6348 KB Output is correct
31 Correct 52 ms 5584 KB Output is correct
32 Correct 24 ms 3804 KB Output is correct
33 Correct 24 ms 3548 KB Output is correct
34 Correct 25 ms 3548 KB Output is correct
35 Correct 12 ms 3316 KB Output is correct
36 Correct 1 ms 2392 KB Output is correct
37 Correct 14 ms 3324 KB Output is correct
38 Correct 20 ms 3548 KB Output is correct
39 Correct 52 ms 4392 KB Output is correct
40 Correct 45 ms 4312 KB Output is correct
41 Correct 95 ms 6344 KB Output is correct
42 Correct 46 ms 5632 KB Output is correct
43 Correct 27 ms 4056 KB Output is correct
44 Correct 47 ms 5336 KB Output is correct
45 Correct 52 ms 6092 KB Output is correct
46 Correct 37 ms 4572 KB Output is correct
47 Correct 55 ms 4572 KB Output is correct
48 Correct 54 ms 4572 KB Output is correct
49 Correct 112 ms 6316 KB Output is correct
50 Correct 51 ms 5420 KB Output is correct
51 Correct 47 ms 4824 KB Output is correct
52 Correct 67 ms 5532 KB Output is correct
53 Correct 62 ms 5552 KB Output is correct
54 Correct 53 ms 6436 KB Output is correct
55 Correct 110 ms 6348 KB Output is correct