Submission #885908

# Submission time Handle Problem Language Result Execution time Memory
885908 2023-12-11T04:05:03 Z nnhzzz Pilot (NOI19_pilot) C++14
100 / 100
648 ms 148792 KB
/* [Author: Nguyen Ngoc Hung] - From THPT Ngo Gia Tu with Love */

#include <bits/stdc++.h>

using namespace std;

#define        __nnhzzz__  signed main()
#define          BIT(i,j)  ((i>>j)&1LL)
#define           MASK(i)  (1LL<<i)
#define            ALL(x)  (x).begin(),(x).end()
#define             SZ(x)  (int)(x).size()
#define               _PB  push_back
#define                fi  first
#define                se  second
#define                ll  long long
#define                ld  long double
#define                vi  vector<int>
#define               vvi  vector<vi>
#define              vvvi  vector<vvi>
#define               pii  pair<int,int>
#define              vpii  vector<pii>
#define             vvpii  vector<vpii>
#define REPDIS(i,be,en,j)  for(int i = (be); i<=(en); i+=j)
#define     REPD(i,be,en)  for(int i = (be); i>=(en); i--)
#define      REP(i,be,en)  for(int i = (be); i<=(en); i++)
#define              endl  "\n"
#define                MP  make_pair
#define               int  ll

//-----------------------------------------------------------------------------------------------//
int readInt(){
    char c;
    do{ c = getchar(); }while(c!='-' && !isdigit(c));
    bool neg = (c=='-');
    int res = neg?0:c-'0';
    while(isdigit(c=getchar())) res = (res<<3)+(res<<1)+(c-'0');
    return neg?-res:res;
}
//------------------------------------------------------------------------------------------------//
const  ll   LINF = 1e18;
const int    INF = 1e9;
const int    LOG = 20;
const int   MAXN = 1e6+3;
const int      N = 1e2+3;
const int    MOD = 1e9+7;
const int   BASE = 1e5;
const  ld    EPS = 1e-9;
const  ld     PI = acos(-1);
const int OFFSET = 1e3;
//------------------------------------------------------------------------------------------------//
template<typename T1, typename T2> bool mini(T1 &a, T2 b){if(a>b){a=b;return true;}return false;}
template<typename T1, typename T2> bool maxi(T1 &a, T2 b){if(a<b){a=b;return true;}return false;}
template<typename T> T gcd(T a, T b) { while(b) { a %= b; swap(a,b); } return a; }
template<typename T> T lcm(T a, T b) { return a/gcd(a,b)*b; }
//------------------------------------------------------------------------------------------------//

/*
----------------------------------------------------------------
    END OF TEMPLATE
----------------------------------------------------------------
    Nguyen Ngoc Hung - nnhzzz
    Training for VOI24 gold medal
----------------------------------------------------------------
*/

int a[MAXN],res[MAXN],q[MAXN];
int n,query;

namespace sub3{
    const int MAX = 2e2+3;
    int f[MAX][MAX];

    void solve(){
        REP(i,1,n){
            int ma = 0;
            REP(j,i,n){
                maxi(ma,a[j]);
                f[i][j] = ma;
            }
        }
        REP(t,1,query){
            int x = q[t],res = 0;
            REP(i,1,n){
                REP(j,i,n){
                    if(f[i][j]>x) break;
                    ++res;
                }
            }
            cout << res << endl;
        }
    }
}

namespace sub11{
    int sum = 0;
    vi adj[MAXN],g[MAXN];
    struct DSU{
        vi par,s;
        int n;

        int find(int u){
            while(u!=par[u]) u = par[u] = par[par[u]];
            return u;
        }

        void unite(int u, int v){
            if(min(u,v)<1 || max(u,v)>n) return ;
            u = find(u); v = find(v);
            if(u==v) return ;
            sum += 1LL*s[u]*s[v];
            if(s[u]<s[v]) swap(u,v);
            s[u] += s[v];
            par[v] = u;
        }

        DSU(int _n):n(_n){
            par.resize(n+3); iota(ALL(par),0);
            s.assign(n+3,1);
        }
    };

    void solve(){
        REP(i,1,n) adj[a[i]].push_back(i);
        REP(i,1,query) g[q[i]].push_back(i);
        DSU dsu(n);
        REP(x,1,MAXN-1){
            for(int &i:adj[x]){
                if(a[i-1]<=x) dsu.unite(i-1,i);
                if(a[i+1]<=x) dsu.unite(i,i+1);
            }
            sum += SZ(adj[x]);
            for(int &i:g[x]) res[i] = sum;
        }
        REP(i,1,query) cout << res[i] << endl;
    }
}

void solve(){
    cin >> n >> query;
    REP(i,1,n) cin >> a[i];
    REP(i,1,query) cin >> q[i];
    sub11::solve(); return ;
    if(n<=200 && query<=200){
        sub3::solve();
        return ;
    }
    sub11::solve();
}

__nnhzzz__{
    ios::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
    #define task "test"
    if(fopen(task".inp","r")){
        freopen(task".inp","r",stdin);
        freopen(task".out","w",stdout);
    }
    #define task1 "nnhzzz"
    if(fopen(task1".inp","r")){
        freopen(task1".inp","r",stdin);
        freopen(task1".out","w",stdout);
    }

    int test = 1;

    while(test--){
        solve();
    }
    cerr << "\nTime elapsed: " << 1000*clock()/CLOCKS_PER_SEC << "ms\n";
    return 0;
}

Compilation message

pilot.cpp: In function 'int main()':
pilot.cpp:155:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
  155 |         freopen(task".inp","r",stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~
pilot.cpp:156:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
  156 |         freopen(task".out","w",stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~
pilot.cpp:160:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
  160 |         freopen(task1".inp","r",stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~
pilot.cpp:161:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
  161 |         freopen(task1".out","w",stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 21 ms 51800 KB Output is correct
2 Correct 14 ms 51804 KB Output is correct
3 Correct 15 ms 51924 KB Output is correct
4 Correct 16 ms 51928 KB Output is correct
5 Correct 14 ms 51804 KB Output is correct
6 Correct 14 ms 51864 KB Output is correct
7 Correct 14 ms 51804 KB Output is correct
8 Correct 14 ms 51800 KB Output is correct
9 Correct 14 ms 51932 KB Output is correct
10 Correct 15 ms 51804 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 21 ms 51800 KB Output is correct
2 Correct 14 ms 51804 KB Output is correct
3 Correct 15 ms 51924 KB Output is correct
4 Correct 16 ms 51928 KB Output is correct
5 Correct 14 ms 51804 KB Output is correct
6 Correct 14 ms 51864 KB Output is correct
7 Correct 14 ms 51804 KB Output is correct
8 Correct 14 ms 51800 KB Output is correct
9 Correct 14 ms 51932 KB Output is correct
10 Correct 15 ms 51804 KB Output is correct
11 Correct 16 ms 51804 KB Output is correct
12 Correct 14 ms 51800 KB Output is correct
13 Correct 14 ms 51804 KB Output is correct
14 Correct 14 ms 51940 KB Output is correct
15 Correct 14 ms 51804 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 21 ms 51800 KB Output is correct
2 Correct 14 ms 51804 KB Output is correct
3 Correct 15 ms 51924 KB Output is correct
4 Correct 16 ms 51928 KB Output is correct
5 Correct 14 ms 51804 KB Output is correct
6 Correct 14 ms 51864 KB Output is correct
7 Correct 14 ms 51804 KB Output is correct
8 Correct 14 ms 51800 KB Output is correct
9 Correct 14 ms 51932 KB Output is correct
10 Correct 15 ms 51804 KB Output is correct
11 Correct 16 ms 51804 KB Output is correct
12 Correct 14 ms 51800 KB Output is correct
13 Correct 14 ms 51804 KB Output is correct
14 Correct 14 ms 51940 KB Output is correct
15 Correct 14 ms 51804 KB Output is correct
16 Correct 14 ms 51876 KB Output is correct
17 Correct 14 ms 51804 KB Output is correct
18 Correct 14 ms 51804 KB Output is correct
19 Correct 14 ms 51804 KB Output is correct
20 Correct 14 ms 51952 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 21 ms 51800 KB Output is correct
2 Correct 14 ms 51804 KB Output is correct
3 Correct 15 ms 51924 KB Output is correct
4 Correct 16 ms 51928 KB Output is correct
5 Correct 14 ms 51804 KB Output is correct
6 Correct 14 ms 51864 KB Output is correct
7 Correct 14 ms 51804 KB Output is correct
8 Correct 14 ms 51800 KB Output is correct
9 Correct 14 ms 51932 KB Output is correct
10 Correct 15 ms 51804 KB Output is correct
11 Correct 16 ms 51804 KB Output is correct
12 Correct 14 ms 51800 KB Output is correct
13 Correct 14 ms 51804 KB Output is correct
14 Correct 14 ms 51940 KB Output is correct
15 Correct 14 ms 51804 KB Output is correct
16 Correct 14 ms 51876 KB Output is correct
17 Correct 14 ms 51804 KB Output is correct
18 Correct 14 ms 51804 KB Output is correct
19 Correct 14 ms 51804 KB Output is correct
20 Correct 14 ms 51952 KB Output is correct
21 Correct 14 ms 51804 KB Output is correct
22 Correct 14 ms 51804 KB Output is correct
23 Correct 16 ms 51920 KB Output is correct
24 Correct 16 ms 51804 KB Output is correct
25 Correct 15 ms 51804 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 29 ms 55816 KB Output is correct
2 Correct 44 ms 57052 KB Output is correct
3 Correct 30 ms 55892 KB Output is correct
4 Correct 49 ms 56408 KB Output is correct
5 Correct 28 ms 55636 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 50 ms 64812 KB Output is correct
2 Correct 58 ms 65104 KB Output is correct
3 Correct 52 ms 64848 KB Output is correct
4 Correct 52 ms 65108 KB Output is correct
5 Correct 53 ms 64832 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 61 ms 65096 KB Output is correct
2 Correct 57 ms 65104 KB Output is correct
3 Correct 69 ms 65224 KB Output is correct
4 Correct 59 ms 65368 KB Output is correct
5 Correct 65 ms 65348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 21 ms 51800 KB Output is correct
2 Correct 14 ms 51804 KB Output is correct
3 Correct 15 ms 51924 KB Output is correct
4 Correct 16 ms 51928 KB Output is correct
5 Correct 14 ms 51804 KB Output is correct
6 Correct 14 ms 51864 KB Output is correct
7 Correct 14 ms 51804 KB Output is correct
8 Correct 14 ms 51800 KB Output is correct
9 Correct 14 ms 51932 KB Output is correct
10 Correct 15 ms 51804 KB Output is correct
11 Correct 29 ms 55816 KB Output is correct
12 Correct 44 ms 57052 KB Output is correct
13 Correct 30 ms 55892 KB Output is correct
14 Correct 49 ms 56408 KB Output is correct
15 Correct 28 ms 55636 KB Output is correct
16 Correct 31 ms 55828 KB Output is correct
17 Correct 45 ms 56920 KB Output is correct
18 Correct 44 ms 57104 KB Output is correct
19 Correct 31 ms 55632 KB Output is correct
20 Correct 45 ms 56944 KB Output is correct
21 Correct 28 ms 55644 KB Output is correct
22 Correct 43 ms 56656 KB Output is correct
23 Correct 30 ms 56156 KB Output is correct
24 Correct 42 ms 56660 KB Output is correct
25 Correct 34 ms 55892 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 21 ms 51800 KB Output is correct
2 Correct 14 ms 51804 KB Output is correct
3 Correct 15 ms 51924 KB Output is correct
4 Correct 16 ms 51928 KB Output is correct
5 Correct 14 ms 51804 KB Output is correct
6 Correct 14 ms 51864 KB Output is correct
7 Correct 14 ms 51804 KB Output is correct
8 Correct 14 ms 51800 KB Output is correct
9 Correct 14 ms 51932 KB Output is correct
10 Correct 15 ms 51804 KB Output is correct
11 Correct 16 ms 51804 KB Output is correct
12 Correct 14 ms 51800 KB Output is correct
13 Correct 14 ms 51804 KB Output is correct
14 Correct 14 ms 51940 KB Output is correct
15 Correct 14 ms 51804 KB Output is correct
16 Correct 14 ms 51876 KB Output is correct
17 Correct 14 ms 51804 KB Output is correct
18 Correct 14 ms 51804 KB Output is correct
19 Correct 14 ms 51804 KB Output is correct
20 Correct 14 ms 51952 KB Output is correct
21 Correct 14 ms 51804 KB Output is correct
22 Correct 14 ms 51804 KB Output is correct
23 Correct 16 ms 51920 KB Output is correct
24 Correct 16 ms 51804 KB Output is correct
25 Correct 15 ms 51804 KB Output is correct
26 Correct 29 ms 55816 KB Output is correct
27 Correct 44 ms 57052 KB Output is correct
28 Correct 30 ms 55892 KB Output is correct
29 Correct 49 ms 56408 KB Output is correct
30 Correct 28 ms 55636 KB Output is correct
31 Correct 50 ms 64812 KB Output is correct
32 Correct 58 ms 65104 KB Output is correct
33 Correct 52 ms 64848 KB Output is correct
34 Correct 52 ms 65108 KB Output is correct
35 Correct 53 ms 64832 KB Output is correct
36 Correct 61 ms 65096 KB Output is correct
37 Correct 57 ms 65104 KB Output is correct
38 Correct 69 ms 65224 KB Output is correct
39 Correct 59 ms 65368 KB Output is correct
40 Correct 65 ms 65348 KB Output is correct
41 Correct 31 ms 55828 KB Output is correct
42 Correct 45 ms 56920 KB Output is correct
43 Correct 44 ms 57104 KB Output is correct
44 Correct 31 ms 55632 KB Output is correct
45 Correct 45 ms 56944 KB Output is correct
46 Correct 28 ms 55644 KB Output is correct
47 Correct 43 ms 56656 KB Output is correct
48 Correct 30 ms 56156 KB Output is correct
49 Correct 42 ms 56660 KB Output is correct
50 Correct 34 ms 55892 KB Output is correct
51 Correct 72 ms 64036 KB Output is correct
52 Correct 73 ms 64848 KB Output is correct
53 Correct 60 ms 64072 KB Output is correct
54 Correct 74 ms 64848 KB Output is correct
55 Correct 73 ms 64068 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 21 ms 51800 KB Output is correct
2 Correct 14 ms 51804 KB Output is correct
3 Correct 15 ms 51924 KB Output is correct
4 Correct 16 ms 51928 KB Output is correct
5 Correct 14 ms 51804 KB Output is correct
6 Correct 14 ms 51864 KB Output is correct
7 Correct 14 ms 51804 KB Output is correct
8 Correct 14 ms 51800 KB Output is correct
9 Correct 14 ms 51932 KB Output is correct
10 Correct 15 ms 51804 KB Output is correct
11 Correct 16 ms 51804 KB Output is correct
12 Correct 14 ms 51800 KB Output is correct
13 Correct 14 ms 51804 KB Output is correct
14 Correct 14 ms 51940 KB Output is correct
15 Correct 14 ms 51804 KB Output is correct
16 Correct 14 ms 51876 KB Output is correct
17 Correct 14 ms 51804 KB Output is correct
18 Correct 14 ms 51804 KB Output is correct
19 Correct 14 ms 51804 KB Output is correct
20 Correct 14 ms 51952 KB Output is correct
21 Correct 14 ms 51804 KB Output is correct
22 Correct 14 ms 51804 KB Output is correct
23 Correct 16 ms 51920 KB Output is correct
24 Correct 16 ms 51804 KB Output is correct
25 Correct 15 ms 51804 KB Output is correct
26 Correct 29 ms 55816 KB Output is correct
27 Correct 44 ms 57052 KB Output is correct
28 Correct 30 ms 55892 KB Output is correct
29 Correct 49 ms 56408 KB Output is correct
30 Correct 28 ms 55636 KB Output is correct
31 Correct 50 ms 64812 KB Output is correct
32 Correct 58 ms 65104 KB Output is correct
33 Correct 52 ms 64848 KB Output is correct
34 Correct 52 ms 65108 KB Output is correct
35 Correct 53 ms 64832 KB Output is correct
36 Correct 61 ms 65096 KB Output is correct
37 Correct 57 ms 65104 KB Output is correct
38 Correct 69 ms 65224 KB Output is correct
39 Correct 59 ms 65368 KB Output is correct
40 Correct 65 ms 65348 KB Output is correct
41 Correct 31 ms 55828 KB Output is correct
42 Correct 45 ms 56920 KB Output is correct
43 Correct 44 ms 57104 KB Output is correct
44 Correct 31 ms 55632 KB Output is correct
45 Correct 45 ms 56944 KB Output is correct
46 Correct 28 ms 55644 KB Output is correct
47 Correct 43 ms 56656 KB Output is correct
48 Correct 30 ms 56156 KB Output is correct
49 Correct 42 ms 56660 KB Output is correct
50 Correct 34 ms 55892 KB Output is correct
51 Correct 72 ms 64036 KB Output is correct
52 Correct 73 ms 64848 KB Output is correct
53 Correct 60 ms 64072 KB Output is correct
54 Correct 74 ms 64848 KB Output is correct
55 Correct 73 ms 64068 KB Output is correct
56 Correct 622 ms 146260 KB Output is correct
57 Correct 611 ms 147284 KB Output is correct
58 Correct 648 ms 142168 KB Output is correct
59 Correct 613 ms 144464 KB Output is correct
60 Correct 628 ms 148792 KB Output is correct