Submission #1276432

#TimeUsernameProblemLanguageResultExecution timeMemory
1276432sasdeFinancial Report (JOI21_financial)C++20
5 / 100
468 ms55620 KiB
#include<bits/stdc++.h>
using namespace std;
bool M1;
#define PI 3.14159265358979323846
#define sz(a) (int)a.size()
#define all(x) x.begin(),x.end()
#define ii pair<int,int>
#define iii pair<int,ii>
#define iv pair<ii,ii>
#define se second
#define fi first
#define ffi fi.fi
#define sfi se.fi
#define sse se.se
#define fse fi.se
#define lt(i, c, d) for(int i = c; i <= d; ++i)
#define fl(i, c, d) for(int i = d; i >= c; --i)
#define pb push_back
#define emb emplace_back
#define emf emplace_front
#define em emplace
#define look_memory cerr<<abs(&M2-&M1)/1024.0/1024<<'\n'
#define look_time   cerr << "TIME : " << clock() * 0.001 << "s" <<'\n'
const int N=1e6+5,lg=30,mod=1e9+7,inf=1e9;
mt19937 rd(chrono::steady_clock::now().time_since_epoch().count());
int Rand(int u,int v){
 return u+rd()%(v-u+1);
}
int dx[]={1,0,-1,0,1,1,-1,-1};
int dy[]={0,-1,0,1,1,-1,1,-1};
int node,k,a[N];
struct segmax {
    int n;
    vector<int> st, lazy;
    segmax() {};
    segmax(int _n): n(_n), st(n * 4 + 5, -inf), lazy(n * 4 + 5, -inf) {};
    void down(int id) {
        if (lazy[id] == -inf) return;
        lazy[id << 1] = lazy[id];
        lazy[id << 1 | 1] = lazy[id];
        st[id << 1] = lazy[id];
        st[id << 1 | 1] = lazy[id];
        lazy[id] = 0;
    }

    void update(int id, int l, int r, int u, int v, int val) {
        if (r < u || l > v) return;
        if (l >= u && r <= v) {
            st[id] = val;
            lazy[id] = val;
            return;
        }
        down(id);
        int mid = (l + r) >> 1;
        update(id << 1, l, mid, u, v, val);
        update(id << 1 | 1, mid + 1, r, u, v, val);
        st[id] = max(st[id << 1], st[id << 1 | 1]);
    }

    int get(int id, int l, int r, int u, int v) {
        if (r < u || l > v) return 0;
        if (l >= u && r <= v) return st[id];
        down(id);
        int mid = (l + r) >> 1;
        return max(get(id << 1, l, mid, u, v), get(id << 1 | 1, mid + 1, r, u, v));
    }

    int getleft(int id, int l, int r, int u, int v, int val) {
        if (st[id] < val || r < u || l > v) return -1;
        if (l == r) return l;
        down(id);
        int mid = (l + r) >> 1;
        int R = getleft(id << 1, l, mid, u, v, val);
        if (R == -1)
            return getleft(id << 1 | 1, mid + 1, r, u, v, val);
        return R;
    }

    int getright(int id, int l, int r, int u, int v, int val) {
        if (st[id] < val || r < u || l > v) return -1;
        if (l == r) return l;
        down(id);
        int mid = (l + r) >> 1;
        int R = getright(id << 1 | 1, mid + 1, r, u, v, val);
        if (R == -1)
            return getright(id << 1, l, mid, u, v, val);
        return R;
    }
};
vector<ii>nen;
vector<int>req[N];
int last[N],vt[N];
bool M2;
void solve(){
	cin >> node >> k;
	for(int i=1;i<=node;++i){
		cin >> a[i];
		nen.emb(a[i],-i);
	}
	sort(all(nen));
	for(int i=1;i<=node;++i){
        a[i]=lower_bound(all(nen),make_pair(a[i],-i))-nen.begin()+1;
        vt[a[i]]=i;
    }
    segmax lay(node);
    set<int>s;
    s.insert(inf);
    for(int i=1;i<=node;++i){
        auto it=s.lower_bound(vt[i]);
        lay.update(1,1,node,vt[i],vt[i],*it-vt[i]);
        last[vt[i]]=lay.getleft(1,1,node,vt[i],node,k);
        s.insert(vt[i]);
    }
	int ans=0,n=sz(nen);
	segmax seg(n);
    seg.update(1,1,node,0,0,0);
	for(int i=1;i<=node;++i){
        for(auto x:req[i])seg.update(1,0,node,x,x,-inf);
		int val=seg.get(1,0,node,1,a[i])+1;
        seg.update(1,0,node,a[i],a[i],val);
        // cout << last[i]<<" ";
        ans=max(ans,val);
        if(last[i]+k+1<=node)req[last[i]+k+1].emb(a[i]);
	}
	cout << ans;

}
main()
{
  srand(time(0));
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    #define task "bhfdj"
    if(fopen(task".inp","r")){
      freopen(task".inp","r",stdin);
      freopen(task".out","w",stdout);
    }
    int t=1;
 //   cin >> t;
while(t--){
    solve();cout<<'\n';
}
look_memory;
look_time;
}

Compilation message (stderr)

Main.cpp:128:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
  128 | main()
      | ^~~~
Main.cpp: In function 'int main()':
Main.cpp:136:14: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
  136 |       freopen(task".inp","r",stdin);
      |       ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~
Main.cpp:137:14: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
  137 |       freopen(task".out","w",stdout);
      |       ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...