Submission #1062014

# Submission time Handle Problem Language Result Execution time Memory
1062014 2024-08-16T16:58:51 Z CodeLakVN Pilot (NOI19_pilot) C++17
63 / 100
34 ms 43088 KB
#include <bits/stdc++.h>

#define no "NO"
#define yes "YES"
#define F first
#define S second
#define vec vector
#define task "PILOT"
#define ll long long
#define _mp make_pair
#define ii pair<int, int>
#define sz(x) (int)x.size()
#define all(x) x.begin(), x.end()
#define evoid(val) return void(std::cout << val)
#define FOR(i, a, b) for(int i = (a); i <= (b); ++i)
#define FOD(i, b, a) for(int i = (b); i >= (a); --i)
#define unq(x) sort(all(x)); x.resize(unique(all(x)) - x.begin())

using namespace std;

template<typename U, typename V> bool maximize(U &a, V b) {
    if (a < b) { a = b; return 1; } return 0;
}
template<typename U, typename V> bool minimize(U &a, V b) {
    if (a > b) { a = b; return 1; } return 0;
}

const int N = (int)1e6 + 9;
const int INF = (int)1e9;
const int MOD = (int)1e9 + 7;

int n, numQuery;
int a[N], query[N];

namespace sub3 {
    bool valid() {
        return max(n, numQuery) <= 200;
    }

    void solve() {
        FOR(i, 1, numQuery) {
            int ans = 0;
            FOR(s, 1, n) {
                if (a[s] > query[i]) continue;
                FOR(e, s, n) {
                    if (a[e] <= query[i]) ans++;
                    else break;
                }
            }
            cout << ans << "\n";
        }
    }
}

namespace sub4 {
    bool valid() {
        return 1LL * n * numQuery <= (ll)1e8;
    }

    void solve() {
        FOR(i, 1, numQuery) {
            int ans = 0;
            FOR(s, 1, n) {
                if (a[s] > query[i]) continue;
                int e = s;
                while (e <=n && a[e] <= query[i]) e++;
                e--;
                int cnt = (e - s + 1);
                ans += cnt * (cnt + 1) / 2;
                s = e;
            }
            cout << ans << "\n";
        }
    }
}

namespace subFull {
    vector<int> pos[N];
    bool vis[N];
    int preLen[N], sufLen[N];
    ll ans[N];

    void solve() {
        int maxVal = *max_element(query + 1, query + numQuery + 1);
        FOR(i, 1, n) pos[a[i]].push_back(i);

        memset(vis, 0, sizeof(vis));

        FOR(i, 1, maxVal) {
            ans[i] = ans[i - 1];
            for (int x : pos[i]) {
                ans[i]++;
                if (vis[x - 1]) ans[i] += preLen[x - 1], sufLen[x - 1 - preLen[x - 1] + 1]++;
                if (vis[x + 1]) ans[i] += sufLen[x + 1], preLen[x + 1 + sufLen[x + 1] - 1]++;
                if (vis[x - 1] && vis[x + 1]) {
                    ans[i] += 1LL * preLen[x - 1] * sufLen[x + 1];
                    sufLen[x - 1 - preLen[x - 1] + 1] += sufLen[x + 1];
                    preLen[x + 1 + sufLen[x + 1] - 1] += preLen[x - 1];
                }
                preLen[x] = preLen[x - 1] + 1;
                sufLen[x] = sufLen[x + 1] + 1;
                vis[x] = 1;
            }
        }

        FOR(i, 1, numQuery) {
            cout << ans[query[i]] << "\n";
        }
    }
}

void main_code() {
    cin >> n >> numQuery;
    FOR(i, 1, n) cin >> a[i];
    FOR(i, 1, numQuery) cin >> query[i];

    if (sub3::valid()) sub3::solve();
    else if (sub4::valid()) sub4::solve();
    else subFull::solve();
}

int main() {
    ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    if (fopen(task".inp", "r")) {
        freopen(task".inp", "r", stdin);
        freopen(task".out", "w", stdout);
    }
    const bool MULTITEST = 0;
    int num_test = 1; if (MULTITEST) cin >> num_test;
    while (num_test--) { main_code(); cout << "\n"; }
}

/* Lak lu theo dieu nhac */

Compilation message

pilot.cpp: In function 'int main()':
pilot.cpp:125:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
  125 |         freopen(task".inp", "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
pilot.cpp:126:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
  126 |         freopen(task".out", "w", stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 4 ms 26972 KB Output is correct
2 Correct 4 ms 26972 KB Output is correct
3 Correct 4 ms 27080 KB Output is correct
4 Correct 4 ms 26972 KB Output is correct
5 Correct 4 ms 26972 KB Output is correct
6 Correct 5 ms 26972 KB Output is correct
7 Correct 5 ms 26968 KB Output is correct
8 Correct 4 ms 26968 KB Output is correct
9 Correct 6 ms 26972 KB Output is correct
10 Correct 4 ms 26972 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 26972 KB Output is correct
2 Correct 4 ms 26972 KB Output is correct
3 Correct 4 ms 27080 KB Output is correct
4 Correct 4 ms 26972 KB Output is correct
5 Correct 4 ms 26972 KB Output is correct
6 Correct 5 ms 26972 KB Output is correct
7 Correct 5 ms 26968 KB Output is correct
8 Correct 4 ms 26968 KB Output is correct
9 Correct 6 ms 26972 KB Output is correct
10 Correct 4 ms 26972 KB Output is correct
11 Correct 4 ms 26972 KB Output is correct
12 Correct 4 ms 26972 KB Output is correct
13 Correct 4 ms 26972 KB Output is correct
14 Correct 4 ms 27084 KB Output is correct
15 Correct 4 ms 26972 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 26972 KB Output is correct
2 Correct 4 ms 26972 KB Output is correct
3 Correct 4 ms 27080 KB Output is correct
4 Correct 4 ms 26972 KB Output is correct
5 Correct 4 ms 26972 KB Output is correct
6 Correct 5 ms 26972 KB Output is correct
7 Correct 5 ms 26968 KB Output is correct
8 Correct 4 ms 26968 KB Output is correct
9 Correct 6 ms 26972 KB Output is correct
10 Correct 4 ms 26972 KB Output is correct
11 Correct 4 ms 26972 KB Output is correct
12 Correct 4 ms 26972 KB Output is correct
13 Correct 4 ms 26972 KB Output is correct
14 Correct 4 ms 27084 KB Output is correct
15 Correct 4 ms 26972 KB Output is correct
16 Correct 5 ms 26972 KB Output is correct
17 Correct 4 ms 27020 KB Output is correct
18 Correct 5 ms 26972 KB Output is correct
19 Correct 5 ms 26972 KB Output is correct
20 Correct 5 ms 27128 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 26972 KB Output is correct
2 Correct 4 ms 26972 KB Output is correct
3 Correct 4 ms 27080 KB Output is correct
4 Correct 4 ms 26972 KB Output is correct
5 Correct 4 ms 26972 KB Output is correct
6 Correct 5 ms 26972 KB Output is correct
7 Correct 5 ms 26968 KB Output is correct
8 Correct 4 ms 26968 KB Output is correct
9 Correct 6 ms 26972 KB Output is correct
10 Correct 4 ms 26972 KB Output is correct
11 Correct 4 ms 26972 KB Output is correct
12 Correct 4 ms 26972 KB Output is correct
13 Correct 4 ms 26972 KB Output is correct
14 Correct 4 ms 27084 KB Output is correct
15 Correct 4 ms 26972 KB Output is correct
16 Correct 5 ms 26972 KB Output is correct
17 Correct 4 ms 27020 KB Output is correct
18 Correct 5 ms 26972 KB Output is correct
19 Correct 5 ms 26972 KB Output is correct
20 Correct 5 ms 27128 KB Output is correct
21 Correct 5 ms 26972 KB Output is correct
22 Correct 5 ms 26972 KB Output is correct
23 Correct 5 ms 26968 KB Output is correct
24 Correct 5 ms 26972 KB Output is correct
25 Correct 4 ms 26968 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 9 ms 27484 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 29 ms 42704 KB Output is correct
2 Correct 27 ms 42764 KB Output is correct
3 Correct 34 ms 42696 KB Output is correct
4 Correct 27 ms 42844 KB Output is correct
5 Correct 27 ms 42584 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 29 ms 42832 KB Output is correct
2 Correct 33 ms 42832 KB Output is correct
3 Correct 32 ms 42704 KB Output is correct
4 Correct 31 ms 43088 KB Output is correct
5 Correct 32 ms 42832 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 26972 KB Output is correct
2 Correct 4 ms 26972 KB Output is correct
3 Correct 4 ms 27080 KB Output is correct
4 Correct 4 ms 26972 KB Output is correct
5 Correct 4 ms 26972 KB Output is correct
6 Correct 5 ms 26972 KB Output is correct
7 Correct 5 ms 26968 KB Output is correct
8 Correct 4 ms 26968 KB Output is correct
9 Correct 6 ms 26972 KB Output is correct
10 Correct 4 ms 26972 KB Output is correct
11 Incorrect 9 ms 27484 KB Output isn't correct
12 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 4 ms 26972 KB Output is correct
2 Correct 4 ms 26972 KB Output is correct
3 Correct 4 ms 27080 KB Output is correct
4 Correct 4 ms 26972 KB Output is correct
5 Correct 4 ms 26972 KB Output is correct
6 Correct 5 ms 26972 KB Output is correct
7 Correct 5 ms 26968 KB Output is correct
8 Correct 4 ms 26968 KB Output is correct
9 Correct 6 ms 26972 KB Output is correct
10 Correct 4 ms 26972 KB Output is correct
11 Correct 4 ms 26972 KB Output is correct
12 Correct 4 ms 26972 KB Output is correct
13 Correct 4 ms 26972 KB Output is correct
14 Correct 4 ms 27084 KB Output is correct
15 Correct 4 ms 26972 KB Output is correct
16 Correct 5 ms 26972 KB Output is correct
17 Correct 4 ms 27020 KB Output is correct
18 Correct 5 ms 26972 KB Output is correct
19 Correct 5 ms 26972 KB Output is correct
20 Correct 5 ms 27128 KB Output is correct
21 Correct 5 ms 26972 KB Output is correct
22 Correct 5 ms 26972 KB Output is correct
23 Correct 5 ms 26968 KB Output is correct
24 Correct 5 ms 26972 KB Output is correct
25 Correct 4 ms 26968 KB Output is correct
26 Incorrect 9 ms 27484 KB Output isn't correct
27 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 4 ms 26972 KB Output is correct
2 Correct 4 ms 26972 KB Output is correct
3 Correct 4 ms 27080 KB Output is correct
4 Correct 4 ms 26972 KB Output is correct
5 Correct 4 ms 26972 KB Output is correct
6 Correct 5 ms 26972 KB Output is correct
7 Correct 5 ms 26968 KB Output is correct
8 Correct 4 ms 26968 KB Output is correct
9 Correct 6 ms 26972 KB Output is correct
10 Correct 4 ms 26972 KB Output is correct
11 Correct 4 ms 26972 KB Output is correct
12 Correct 4 ms 26972 KB Output is correct
13 Correct 4 ms 26972 KB Output is correct
14 Correct 4 ms 27084 KB Output is correct
15 Correct 4 ms 26972 KB Output is correct
16 Correct 5 ms 26972 KB Output is correct
17 Correct 4 ms 27020 KB Output is correct
18 Correct 5 ms 26972 KB Output is correct
19 Correct 5 ms 26972 KB Output is correct
20 Correct 5 ms 27128 KB Output is correct
21 Correct 5 ms 26972 KB Output is correct
22 Correct 5 ms 26972 KB Output is correct
23 Correct 5 ms 26968 KB Output is correct
24 Correct 5 ms 26972 KB Output is correct
25 Correct 4 ms 26968 KB Output is correct
26 Incorrect 9 ms 27484 KB Output isn't correct
27 Halted 0 ms 0 KB -