답안 #635016

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
635016 2022-08-25T10:10:58 Z minhcool 즐거운 채소 기르기 (JOI14_growing) C++17
100 / 100
102 ms 10732 KB
//#include "ramen.h"
#include<bits/stdc++.h>
using namespace std;
 
#define int long long
#define fi first
#define se second
#define pb push_back
//#define mp make_pair
#define foru(i, l, r) for(int i = l; i <= r; i++)
#define ford(i, r, l) for(int i = r; i >= l; i--)
 
typedef pair<int, int> ii;
typedef pair<ii, int> iii;
typedef pair<ii, ii> iiii;
 
const int N = 4e5 + 5;
 
const int oo = 1e18 + 7, mod = 1e9 + 7;
 
int n, a[N];
 
int BIT[N];
 
void upd(int id, int val){
    for(; id <= n; id += id & -id) BIT[id] += val;
}
 
int get(int id){
    int ans = 0;
    for(; id; id -= id & -id) ans += BIT[id];
    return ans;
}
 
vector<ii> vc;
 
bool cmp(ii a, ii b){
    return (a.fi > b.fi);
}
 
void process(){
    cin >> n;
    for(int i = 1; i <= n; i++){
        cin >> a[i];
        vc.pb({a[i], i});
    }
    sort(vc.begin(), vc.end(), cmp);
    int answer = 0, itr = 0;
    for(auto it : vc){
        while(vc[itr].fi > it.fi){
            upd(vc[itr].se, 1);
            itr++;
        }
        //cout << it.fi << " " << it.se << " " << itr << " " << get(it.se - 1) << " ""\n";
        answer += min(get(it.se - 1), get(n) - get(it.se));
    }
    cout << answer;
}
 
signed main(){
	ios_base::sync_with_stdio(0);
	process();
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 340 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 0 ms 340 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 340 KB Output is correct
5 Correct 0 ms 340 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 0 ms 328 KB Output is correct
10 Correct 0 ms 340 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 468 KB Output is correct
5 Correct 2 ms 596 KB Output is correct
6 Correct 1 ms 596 KB Output is correct
7 Correct 1 ms 596 KB Output is correct
8 Correct 2 ms 596 KB Output is correct
9 Correct 1 ms 596 KB Output is correct
10 Correct 2 ms 596 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 12 ms 2256 KB Output is correct
2 Correct 26 ms 3596 KB Output is correct
3 Correct 38 ms 5580 KB Output is correct
4 Correct 57 ms 6700 KB Output is correct
5 Correct 41 ms 6632 KB Output is correct
6 Correct 23 ms 3532 KB Output is correct
7 Correct 49 ms 10656 KB Output is correct
8 Correct 102 ms 10660 KB Output is correct
9 Correct 76 ms 10732 KB Output is correct
10 Correct 85 ms 10676 KB Output is correct