답안 #583183

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
583183 2022-06-25T02:59:54 Z Joshi503 Mountains (NOI20_mountains) C++14
24 / 100
525 ms 28032 KB
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using db = long double;
using str = string;
using pi = pair<int, int>;
using pl = pair<ll, ll>;
using pd = pair<db, db>;
#define f first
#define s second

#define tcT template<class T
#define tcTU tcT, class U
tcT> using V = vector<T>;
tcT, size_t SZ > using AR = array<T, SZ>;
using vi = V<int>;
using vb = V<bool>;
using vl = V<ll>;
using vd = V<db>;
using vs = V<str>;
using vpi = V<pi>;
using vpl = V<pl>;

#define sz(x) int((x).size())
#define bg(x) begin(x)
#define all(x) bg(x), end(x)
#define rall(x) x.rbegin(), x.rend() 
#define sor(x) sort(all(x)) 
#define pb push_back

#define FOR(i,a,b) for (int i = (a); i < (b); ++i)
#define F0R(i,a) FOR(i,0,a)
#define ROF(i,a,b) for (int i = ((b)-1); i >= (a); --i)
#define R0F(i,a) ROF(i,0,a)
#define rep(a) F0R(_,a)
#define each(a,x) for (auto& a: x)

const ll MOD = 1e9 + 7;
const ll MX = 1e9;
const ll INF = 1e18;
const db PI = acos((db)-1);
const int ddef[4]{ 1,0,-1,0 }, dataq[4]{ 0,1,0,-1 };
mt19937 rng((uint32_t)chrono::steady_clock::now().time_since_epoch().count());
template<class T> using pqg = priority_queue<T, vector<T>, greater<T>>;
void setIO(string name = "") {
    ios_base::sync_with_stdio(0); cin.tie(0);
    if (sz(name)) {
        freopen((name + ".in").c_str(), "r", stdin);
        freopen((name + ".out").c_str(), "w", stdout);
    }
}
void _print(char i) { cerr << i; }
void _print(string i) { cerr << i; }
void _print(float i) { cerr << i; }
void _print(int i) { cerr << i; }
void _print(double i) { cerr << i; }
void _print() { cerr << "\n"; };
template<typename x, typename y> void _print(pair<x, y>& t) { cerr << "{";_print(t.first);cerr << ", ";_print(t.second);cerr << "},"; }
template<typename x> void _print(x& t) { cerr << "{"; for (int i = 0;i < (int)t.size();i++) { _print(t[i]); if (i < (int)t.size() - 1) cerr << ", "; } cerr << "}"; }
template<typename x, typename... y> void _print(x a, y... b) { _print(a);if (sizeof...(b)) cerr << ", ";_print(b...); }
#define dbg(x...) cerr<<"["<<#x<<"] = [";_print(x);cerr<<"]\n";
int test;
const int MXN = 3e5;
int a[MXN + 5];

struct ST{
    int n; 
    vl st;
    ST(int n1){
        n = n1;
        st = vl(n * 4 + 5, 0);
    }

    int left(int node) { return 2 * node; }
    int right(int node) { return 2 * node + 1; }
    void calc(int node) { st[node] = st[left(node)] + st[right(node)]; }
    
    void update(int k, int v, int tr, int tl = 1, int node = 1){
        if(tl == tr){
            st[node] += v;
            return;
        }
        int mid = (tl + tr) / 2;
        if(k >= tl && k <= mid){
            update(k, v, mid, tl, left(node));
        }
        else update(k, v, tr, mid + 1, right(node));
        calc(node);
    }

    ll query(int ql, int qr, int tr, int tl = 1, int node = 1){
        if(tl >= ql && tr <= qr){
            return st[node];
        }
        if(tr < ql || tl > qr){
            return 0LL;
        }
        int mid = (tl + tr) / 2;
        return query(ql, qr, mid, tl, left(node)) + query(ql, qr, tr, mid + 1, right(node));
    }
};

void solve() {
    int n;
    cin >> n;
    F0R(i, n){
        cin >> a[i];
    }
    map<ll, int> m;
    F0R(i, n){
        m[a[i]] = 1;
    }
    int idx = 1;
    each(x, m){
        m[x.f] = idx++;
    }
    ST st1(n), st2(n);
    F0R(i, n){
        a[i] = m[a[i]];
        st1.update(a[i], 1, n);
    }
    ll ans = 0;
    F0R(i, n){
        st1.update(a[i], -1, n);
        ll x = st1.query(1, a[i] - 1, n), y = st2.query(1, a[i] - 1, n);
        ans += x * y; 
        st2.update(a[i], 1, n);
    }
    cout << ans << "\n";
 
}

int main() {
    setIO("");
    int T = 1;
    // cin >> T;
    for (test = 1; test <= T; test++) solve();
    return 0;
}

Compilation message

Mountains.cpp: In function 'void setIO(std::string)':
Mountains.cpp:48:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   48 |         freopen((name + ".in").c_str(), "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Mountains.cpp:49:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   49 |         freopen((name + ".out").c_str(), "w", stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 71 ms 20276 KB Output is correct
3 Correct 70 ms 20264 KB Output is correct
4 Correct 67 ms 20408 KB Output is correct
5 Correct 70 ms 20408 KB Output is correct
6 Correct 76 ms 20328 KB Output is correct
7 Correct 73 ms 20336 KB Output is correct
8 Correct 63 ms 20300 KB Output is correct
9 Correct 66 ms 20440 KB Output is correct
10 Correct 66 ms 20304 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 110 ms 20300 KB Output is correct
2 Correct 123 ms 20832 KB Output is correct
3 Correct 124 ms 20876 KB Output is correct
4 Correct 107 ms 20812 KB Output is correct
5 Correct 112 ms 20868 KB Output is correct
6 Correct 113 ms 20872 KB Output is correct
7 Correct 126 ms 20948 KB Output is correct
8 Correct 108 ms 20832 KB Output is correct
9 Correct 109 ms 20812 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 110 ms 20300 KB Output is correct
2 Correct 123 ms 20832 KB Output is correct
3 Correct 124 ms 20876 KB Output is correct
4 Correct 107 ms 20812 KB Output is correct
5 Correct 112 ms 20868 KB Output is correct
6 Correct 113 ms 20872 KB Output is correct
7 Correct 126 ms 20948 KB Output is correct
8 Correct 108 ms 20832 KB Output is correct
9 Correct 109 ms 20812 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 166 ms 21216 KB Output is correct
12 Correct 183 ms 21160 KB Output is correct
13 Correct 172 ms 21044 KB Output is correct
14 Correct 168 ms 21012 KB Output is correct
15 Correct 175 ms 21148 KB Output is correct
16 Correct 189 ms 21148 KB Output is correct
17 Correct 158 ms 21060 KB Output is correct
18 Correct 138 ms 21148 KB Output is correct
19 Correct 131 ms 21148 KB Output is correct
20 Correct 1 ms 212 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 340 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 340 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 110 ms 20300 KB Output is correct
2 Correct 123 ms 20832 KB Output is correct
3 Correct 124 ms 20876 KB Output is correct
4 Correct 107 ms 20812 KB Output is correct
5 Correct 112 ms 20868 KB Output is correct
6 Correct 113 ms 20872 KB Output is correct
7 Correct 126 ms 20948 KB Output is correct
8 Correct 108 ms 20832 KB Output is correct
9 Correct 109 ms 20812 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 166 ms 21216 KB Output is correct
12 Correct 183 ms 21160 KB Output is correct
13 Correct 172 ms 21044 KB Output is correct
14 Correct 168 ms 21012 KB Output is correct
15 Correct 175 ms 21148 KB Output is correct
16 Correct 189 ms 21148 KB Output is correct
17 Correct 158 ms 21060 KB Output is correct
18 Correct 138 ms 21148 KB Output is correct
19 Correct 131 ms 21148 KB Output is correct
20 Correct 1 ms 212 KB Output is correct
21 Correct 486 ms 27972 KB Output is correct
22 Correct 495 ms 27956 KB Output is correct
23 Correct 519 ms 27964 KB Output is correct
24 Correct 492 ms 27956 KB Output is correct
25 Correct 509 ms 27956 KB Output is correct
26 Correct 490 ms 27968 KB Output is correct
27 Correct 525 ms 28032 KB Output is correct
28 Correct 228 ms 27956 KB Output is correct
29 Correct 244 ms 27960 KB Output is correct
30 Correct 1 ms 212 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 71 ms 20276 KB Output is correct
3 Correct 70 ms 20264 KB Output is correct
4 Correct 67 ms 20408 KB Output is correct
5 Correct 70 ms 20408 KB Output is correct
6 Correct 76 ms 20328 KB Output is correct
7 Correct 73 ms 20336 KB Output is correct
8 Correct 63 ms 20300 KB Output is correct
9 Correct 66 ms 20440 KB Output is correct
10 Correct 66 ms 20304 KB Output is correct
11 Correct 110 ms 20300 KB Output is correct
12 Correct 123 ms 20832 KB Output is correct
13 Correct 124 ms 20876 KB Output is correct
14 Correct 107 ms 20812 KB Output is correct
15 Correct 112 ms 20868 KB Output is correct
16 Correct 113 ms 20872 KB Output is correct
17 Correct 126 ms 20948 KB Output is correct
18 Correct 108 ms 20832 KB Output is correct
19 Correct 109 ms 20812 KB Output is correct
20 Correct 1 ms 212 KB Output is correct
21 Correct 166 ms 21216 KB Output is correct
22 Correct 183 ms 21160 KB Output is correct
23 Correct 172 ms 21044 KB Output is correct
24 Correct 168 ms 21012 KB Output is correct
25 Correct 175 ms 21148 KB Output is correct
26 Correct 189 ms 21148 KB Output is correct
27 Correct 158 ms 21060 KB Output is correct
28 Correct 138 ms 21148 KB Output is correct
29 Correct 131 ms 21148 KB Output is correct
30 Correct 1 ms 212 KB Output is correct
31 Incorrect 1 ms 340 KB Output isn't correct
32 Halted 0 ms 0 KB -