제출 #1186913

#제출 시각아이디문제언어결과실행 시간메모리
1186913vusalPilot (NOI19_pilot)C++20
55 / 100
1094 ms2272 KiB
#include <bits/stdc++.h>
// author: vusal
#include <ext/pb_ds/assoc_container.hpp>
using namespace std;
using namespace __gnu_pbds;

template<typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

#define int long long

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

const int oo = 1e18 + 9;
const int sz = 2e6+7;
const int MOD = 1e9+7;

void solve() {
    int n, q;
    cin >> n >> q;

    vector<int>h(n), y(q);

    for(int &i : h) cin >> i;
    for(int &i : y) cin >> i;

    for(int he : y)
    {
        int st = 0,  sum = 0;
        while(st < n)
        {
            if(h[st] > he)
            {
                st++;
                continue;
            }

            int nd = st;
            while(nd < n && h[nd] <= he) nd++;

            sum += ((nd - st) * (nd - st + 1) / 2);

            st = nd + 1;
        }
        cout << sum << endl;
    }
}

signed main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int tc = 1;
    // cin >> tc;
    for(int i = 1; i <= tc; i++)
    {
        //cout << "Case " << i << ":";
        solve();
    }
    return 0;
}
#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...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...