이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include<bits/stdc++.h>
#include<fstream>
using namespace std;
ifstream fin("VNOICUP.INP");
ofstream fout("VNOICUP.OUT");
#define sz(a) (int)a.size()
#define ll long long
#define pb push_back
#define forr(i, a, b) for(int i = a; i < b; i++)
#define dorr(i, a, b) for(int i = a; i >= b; i--)
#define ld long double
#define vt vector
#include<fstream>
#define fi first
#define se second
#define pll pair<ll, ll>
#define pii pair<int, int>
const ld PI = 3.14159265359;
const ll mod = 1e9 + 7;
const int mxn = 1e6, mxm = 1e5;
int n, q;
int h[mxn + 1], y[mxn + 1];
ll a[mxn + 1], res[mxn + 1];
set<int>bad;
ll ans = 0;
ll sm(ll x){
return(x * (x + 1) / 2);
}
void rem(int id){
auto low = bad.lower_bound(id); --low;
auto high = bad.upper_bound(id);
ans -= sm(*high - *low - 1);
ans += sm(id - *low - 1); ans += sm(*high - id - 1);
bad.insert(id);
}
signed main(){
ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
cin >> n >> q;
ans = 1LL * n * (n + 1) / 2;
vt<pii>comp;
for(int i = 1; i <= n; i++){
cin >> a[i]; comp.pb(make_pair(a[i], i));
}
bad.insert(0); bad.insert(n + 1);
vt<pii>queries;
forr(i, 0, q){
int y; cin >> y;
queries.pb({y, i});
}
sort(queries.rbegin(), queries.rend()); sort(comp.rbegin(), comp.rend());
int r = 0;
for(auto [y, id]: queries){
while(r < sz(comp) && comp[r].fi > y){
rem(comp[r].se); r++;
}
res[id] = ans;
}
forr(i, 0, q){
cout << res[i] << "\n";
}
return(0);
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |