# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
519839 |
2022-01-27T11:39:22 Z |
idas |
Global Warming (CEOI18_glo) |
C++11 |
|
2000 ms |
13200 KB |
#include <bits/stdc++.h>
#define FOR(i, begin, end) for(int i = (begin); i < (end); i++)
#define FAST_IO ios_base::sync_with_stdio(0); cin.tie(nullptr); cout.tie(nullptr)
#define f first
#define s second
#define pb push_back
#define sz(x) ((int)((x).size()))
#define le(vec) vec[vec.size()-1]
#define all(x) (x).begin(), (x).end()
#define TSTS int ttt; cin >> ttt; while(ttt--) solve()
using namespace std;
typedef pair<int, int> pii;
typedef pair<long long, long long> pll;
typedef pair<long double, long double> pdd;
typedef map<int, int> mii;
typedef vector<int> vi;
typedef long double ld;
typedef long long ll;
const int INF=1e9, MOD=1e9+7, mod=998244353;
const ll LINF=1e18;
void setIO()
{
FAST_IO;
}
void setIO(string s)
{
FAST_IO;
freopen((s+".in").c_str(), "r", stdin);
freopen((s+".out").c_str(), "w", stdout);
}
const int N=2e5+10;
int n, x, t[N], d[N], p[N], st[4*N];
void build(int l=1, int r=n, int id=1)
{
if(l==r){
st[id]=t[l-1];
return;
}
int m=(l+r)/2;
build(l, m, id*2);
build(m+1, r, id*2+1);
st[id]=max(st[id*2], st[id*2+1]);
}
void rem(int in, int l=1, int r=n, int id=1)
{
if(l>r) return;
if(l==r){
if(l==in)
st[in]=0;
}
else{
int m=(l+r)/2;
rem(in, l, m, id*2);
rem(in, m+1, r, id*2+1);
st[id]=max(st[id*2], st[id*2+1]);
}
}
int walk(int val, int l=1, int r=n, int id=1)
{
if(l>r) return N-1;
if(l==r) return l-1;
int m=(l+r)/2;
if(st[id*2+1]==val) return walk(val, l, m, id*2+1);
else return walk(val, m+1, r, id*2);
}
int main()
{
setIO();
cin >> n >> x;
multiset<int> vals;
FOR(i, 0, n) cin >> t[i], vals.insert(t[i]);
build();
vi lds;
for(int i=n-1; i>=0; i--){
int l=0, r=sz(lds);
while(l<r){
int m=(l+r)/2;
if(lds[m]>t[i]) l=m+1;
else r=m;
}
if(l==sz(lds)) lds.pb(t[i]);
else lds[l]=t[i];
d[i]=sz(lds);
}
vi lis; int mx=0;
FOR(i, 0, n)
{
rem(i+1);
vals.erase(*vals.find(t[i]));
t[i]-=x;
int in=lower_bound(all(lis), t[i])-lis.begin();
if(in==sz(lis)) lis.pb(t[i]);
int val=*vals.lower_bound(t[i]);
int idx=walk(val);
if(t[idx]>t[i]){
mx=max(mx, d[idx]+sz(lis));
}
}
cout << mx;
}
Compilation message
glo.cpp: In function 'void setIO(std::string)':
glo.cpp:32:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
32 | freopen((s+".in").c_str(), "r", stdin);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
glo.cpp:33:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
33 | freopen((s+".out").c_str(), "w", stdout);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
332 KB |
Output is correct |
2 |
Incorrect |
0 ms |
320 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
332 KB |
Output is correct |
2 |
Incorrect |
0 ms |
320 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
332 KB |
Output is correct |
2 |
Incorrect |
0 ms |
320 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
2072 ms |
13200 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
2078 ms |
3516 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
2047 ms |
6724 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
332 KB |
Output is correct |
2 |
Incorrect |
0 ms |
320 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |