Submission #1054825

#TimeUsernameProblemLanguageResultExecution timeMemory
1054825cpdreamerFinancial Report (JOI21_financial)C++14
12 / 100
124 ms20564 KiB
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <utility>
#define V vector
#define P pair
#define S second
#define F first
#define pb push_back
#define all(v) v.begin(),v.end()
typedef long long ll;
using namespace __gnu_pbds;
using namespace std;
typedef tree<int,null_type,less<int>,rb_tree_tag,
        tree_order_statistics_node_update> indexed_set;
static int called = 0;const long long MOD = 1e9+7; // 1e9 + 7

void file(){
    freopen("input.txt.txt","r",stdin);
    freopen("output.txt.txt","w",stdout);
}
void file(string s) {
    freopen((s + ".in").c_str(), "r", stdin);
    freopen((s + ".out").c_str(), "w", stdout);
}
int dp[(int)2e6+1];
void solve() {
    int n;
    cin >> n;
    int d;
    int A[n];
    cin >> d;
    for (int i = 0; i < n; i++)
        cin >> A[i];
    dp[n - 1] = 1;
    set<int> st;
    map<int, int> mp;
    mp[A[n - 1]]++;
    for (int i = n - 2; i >= 0; i--) {
        mp[A[i]]++;
        auto it = mp.find(A[i]);
        int c = 0;
        for (auto j = it;;) {
            auto ad=prev(j);
            c += j->S;
            if (j == mp.begin())
                break;
            j=ad;
        }
        for (auto j = it;;) {
            if(j==mp.begin()){
                mp.erase(j);
                break;
            }
            else{
                auto ad=prev(j);
                mp.erase(j);
                j=ad;
            }
        }
        dp[i] = dp[i + 1] - c + 2;
        mp[A[i]]++;
    }
    int ans=0;
    for(int i=0;i<n;i++)
        ans=max(ans,dp[i]);
    cout<<ans<<endl;
}
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    //file();
    solve();
    return 0;
}

Compilation message (stderr)

Main.cpp: In function 'void file()':
Main.cpp:18:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   18 |     freopen("input.txt.txt","r",stdin);
      |     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~
Main.cpp:19:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   19 |     freopen("output.txt.txt","w",stdout);
      |     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Main.cpp: In function 'void file(std::string)':
Main.cpp:22:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   22 |     freopen((s + ".in").c_str(), "r", stdin);
      |     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Main.cpp:23:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   23 |     freopen((s + ".out").c_str(), "w", stdout);
      |     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Main.cpp: At global scope:
Main.cpp:15:12: warning: 'called' defined but not used [-Wunused-variable]
   15 | static int called = 0;const long long MOD = 1e9+7; // 1e9 + 7
      |            ^~~~~~
#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...