제출 #1125829

#제출 시각아이디문제언어결과실행 시간메모리
1125829hainam2k9Financial Report (JOI21_financial)C++20
100 / 100
500 ms23332 KiB
#include <bits/stdc++.h>
#define tt cin.tie(0), cout.tie(0), ios_base::sync_with_stdio(0)
#define fo freopen((NAME+".INP").c_str(), "r", stdin), freopen((NAME+".OUT").c_str(), "w", stdout)
#define ll long long
#define ull unsigned long long
#define i128 __int128
#define db long double
#define sz(a) ((int)(a).size())
#define pb emplace_back
#define pf emplace_front
#define pob pop_back
#define pof pop_front
#define lb lower_bound
#define ub upper_bound
#define fi first
#define se second
#define ins emplace
#define mp make_pair
using namespace std;
const int MOD = 1e9+7, MAXN = 3e5+5;
const string NAME = "";
int n,d,dp[MAXN],sgt[MAXN<<2];
pair<int,int> a[MAXN];
set<int> s;
struct DSU{
    int p[MAXN];
    void init(){
        iota(p+1,p+n+1,1);
    }
    int Find(int u){
        if(u==p[u]) return u;
        return p[u]=Find(p[u]);
    }
    void Union(int a, int b){
        a=Find(a), b=Find(b);
        if(a!=b){
            if(a>b) swap(a,b);
            p[b]=a;
        }
    }
}dsu;
void update(int id, int l, int r, int pos, int val){
    if(pos<l||r<pos) return;
    if(l==r){
        sgt[id]=val;
        return;
    }
    int mid=(l+r)>>1;
    update(id<<1,l,mid,pos,val);
    update(id<<1|1,mid+1,r,pos,val);
    sgt[id]=max(sgt[id<<1],sgt[id<<1|1]);
}
int getmax(int id, int l, int r, int u, int v){
    if(v<l||r<u) return 0;
    if(u<=l&&r<=v) return sgt[id];
    int mid=(l+r)>>1;
    return max(getmax(id<<1,l,mid,u,v),getmax(id<<1|1,mid+1,r,u,v));
}
int main()
{
    tt;
    if(fopen((NAME + ".INP").c_str(), "r")) fo;
    cin >> n >> d;
    for(int i = 1; i<=n; ++i)
        cin >> a[i].fi, a[i].se=i;
    sort(a+1,a+n+1);
    dsu.init();
    fill(dp+1,dp+n+1,1);
    for(int i = 1; i<=n; ++i){
        int pos;
        if(s.empty()||*s.begin()>a[i].se) pos=max(1,a[i].se-d);
        else{
            int pre=*prev(s.lb(a[i].se));
            if(a[i].se-pre<=d) pos=dsu.Find(pre);
            else pos=max(1,a[i].se-d);
        }
        dp[a[i].se]=getmax(1,1,n,pos,max(1,a[i].se-1))+1;
        if(a[i].fi!=a[i+1].fi){
            for(int j = i; j>0; --j){
                s.ins(a[j].se);
                if(*s.begin()<a[j].se){
                    int pre=*prev(s.lb(a[j].se));
                    if(a[j].se-pre<=d) dsu.Union(a[j].se,pre);
                }
                if(*s.rbegin()>a[j].se){
                    int nxt=*s.ub(a[j].se);
                    if(nxt-a[j].se<=d) dsu.Union(a[j].se,nxt);
                }
                update(1,1,n,a[j].se,dp[a[j].se]);
                if(a[j].fi!=a[j-1].fi) break;
            }
        }
    }
    cout << *max_element(dp+1,dp+n+1);
}

컴파일 시 표준 에러 (stderr) 메시지

Main.cpp: In function 'int main()':
Main.cpp:3:19: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
    3 | #define fo freopen((NAME+".INP").c_str(), "r", stdin), freopen((NAME+".OUT").c_str(), "w", stdout)
      |            ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Main.cpp:62:45: note: in expansion of macro 'fo'
   62 |     if(fopen((NAME + ".INP").c_str(), "r")) fo;
      |                                             ^~
Main.cpp:3:63: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
    3 | #define fo freopen((NAME+".INP").c_str(), "r", stdin), freopen((NAME+".OUT").c_str(), "w", stdout)
      |                                                        ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Main.cpp:62:45: note: in expansion of macro 'fo'
   62 |     if(fopen((NAME + ".INP").c_str(), "r")) fo;
      |                                             ^~
#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...