답안 #583190

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
583190 2022-06-25T03:19:49 Z Joshi503 Mountains (NOI20_mountains) C++14
100 / 100
565 ms 26388 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;
ll a[MXN + 5];

struct FT{
    int n; vl ft; 
    FT(int n1){
        n = n1 + 1;
        ft.assign(n, 0);
    }

    ll lsb(ll x) { return x & -x; }

    ll query(ll i){
        ll sum = 0;
        for(; i > 0; i -= lsb(i)) sum += ft[i];
        return sum;
    }

    void update(ll i, int v){
        for(; i <= n; i += lsb(i)) ft[i] += v;  
    }


};

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++;
    }
    FT ft1(n), ft2(n);
    F0R(i, n){
        a[i] = m[a[i]];
        ft1.update(a[i], 1);
    }
    ll ans = 0;
    F0R(i, n){
        ft1.update(a[i], -1);
        ll x = ft1.query(a[i] - 1), y = ft2.query(a[i] - 1);
        ans += x * y; 
        ft2.update(a[i], 1);
    }
    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 0 ms 212 KB Output is correct
2 Correct 218 ms 26048 KB Output is correct
3 Correct 233 ms 26108 KB Output is correct
4 Correct 215 ms 26156 KB Output is correct
5 Correct 230 ms 26120 KB Output is correct
6 Correct 237 ms 26092 KB Output is correct
7 Correct 214 ms 26056 KB Output is correct
8 Correct 214 ms 26056 KB Output is correct
9 Correct 212 ms 17048 KB Output is correct
10 Correct 192 ms 17100 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 101 ms 7380 KB Output is correct
2 Correct 120 ms 7308 KB Output is correct
3 Correct 96 ms 7360 KB Output is correct
4 Correct 110 ms 7356 KB Output is correct
5 Correct 106 ms 7288 KB Output is correct
6 Correct 88 ms 7456 KB Output is correct
7 Correct 102 ms 7372 KB Output is correct
8 Correct 107 ms 7364 KB Output is correct
9 Correct 106 ms 7380 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 101 ms 7380 KB Output is correct
2 Correct 120 ms 7308 KB Output is correct
3 Correct 96 ms 7360 KB Output is correct
4 Correct 110 ms 7356 KB Output is correct
5 Correct 106 ms 7288 KB Output is correct
6 Correct 88 ms 7456 KB Output is correct
7 Correct 102 ms 7372 KB Output is correct
8 Correct 107 ms 7364 KB Output is correct
9 Correct 106 ms 7380 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Correct 109 ms 7376 KB Output is correct
12 Correct 126 ms 7376 KB Output is correct
13 Correct 115 ms 7368 KB Output is correct
14 Correct 106 ms 7372 KB Output is correct
15 Correct 103 ms 7380 KB Output is correct
16 Correct 96 ms 7380 KB Output is correct
17 Correct 120 ms 7360 KB Output is correct
18 Correct 83 ms 7372 KB Output is correct
19 Correct 87 ms 7384 KB Output is correct
20 Correct 1 ms 212 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 340 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 0 ms 212 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 340 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Correct 6 ms 1108 KB Output is correct
12 Correct 7 ms 1108 KB Output is correct
13 Correct 7 ms 1108 KB Output is correct
14 Correct 6 ms 1156 KB Output is correct
15 Correct 7 ms 1136 KB Output is correct
16 Correct 7 ms 1108 KB Output is correct
17 Correct 8 ms 1156 KB Output is correct
18 Correct 8 ms 724 KB Output is correct
19 Correct 4 ms 568 KB Output is correct
20 Correct 1 ms 212 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 101 ms 7380 KB Output is correct
2 Correct 120 ms 7308 KB Output is correct
3 Correct 96 ms 7360 KB Output is correct
4 Correct 110 ms 7356 KB Output is correct
5 Correct 106 ms 7288 KB Output is correct
6 Correct 88 ms 7456 KB Output is correct
7 Correct 102 ms 7372 KB Output is correct
8 Correct 107 ms 7364 KB Output is correct
9 Correct 106 ms 7380 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Correct 109 ms 7376 KB Output is correct
12 Correct 126 ms 7376 KB Output is correct
13 Correct 115 ms 7368 KB Output is correct
14 Correct 106 ms 7372 KB Output is correct
15 Correct 103 ms 7380 KB Output is correct
16 Correct 96 ms 7380 KB Output is correct
17 Correct 120 ms 7360 KB Output is correct
18 Correct 83 ms 7372 KB Output is correct
19 Correct 87 ms 7384 KB Output is correct
20 Correct 1 ms 212 KB Output is correct
21 Correct 259 ms 13444 KB Output is correct
22 Correct 245 ms 13308 KB Output is correct
23 Correct 262 ms 13340 KB Output is correct
24 Correct 282 ms 13376 KB Output is correct
25 Correct 301 ms 13312 KB Output is correct
26 Correct 238 ms 13212 KB Output is correct
27 Correct 269 ms 13272 KB Output is correct
28 Correct 163 ms 13304 KB Output is correct
29 Correct 154 ms 13236 KB Output is correct
30 Correct 1 ms 212 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 218 ms 26048 KB Output is correct
3 Correct 233 ms 26108 KB Output is correct
4 Correct 215 ms 26156 KB Output is correct
5 Correct 230 ms 26120 KB Output is correct
6 Correct 237 ms 26092 KB Output is correct
7 Correct 214 ms 26056 KB Output is correct
8 Correct 214 ms 26056 KB Output is correct
9 Correct 212 ms 17048 KB Output is correct
10 Correct 192 ms 17100 KB Output is correct
11 Correct 101 ms 7380 KB Output is correct
12 Correct 120 ms 7308 KB Output is correct
13 Correct 96 ms 7360 KB Output is correct
14 Correct 110 ms 7356 KB Output is correct
15 Correct 106 ms 7288 KB Output is correct
16 Correct 88 ms 7456 KB Output is correct
17 Correct 102 ms 7372 KB Output is correct
18 Correct 107 ms 7364 KB Output is correct
19 Correct 106 ms 7380 KB Output is correct
20 Correct 0 ms 212 KB Output is correct
21 Correct 109 ms 7376 KB Output is correct
22 Correct 126 ms 7376 KB Output is correct
23 Correct 115 ms 7368 KB Output is correct
24 Correct 106 ms 7372 KB Output is correct
25 Correct 103 ms 7380 KB Output is correct
26 Correct 96 ms 7380 KB Output is correct
27 Correct 120 ms 7360 KB Output is correct
28 Correct 83 ms 7372 KB Output is correct
29 Correct 87 ms 7384 KB Output is correct
30 Correct 1 ms 212 KB Output is correct
31 Correct 1 ms 340 KB Output is correct
32 Correct 1 ms 340 KB Output is correct
33 Correct 1 ms 340 KB Output is correct
34 Correct 1 ms 340 KB Output is correct
35 Correct 1 ms 340 KB Output is correct
36 Correct 1 ms 340 KB Output is correct
37 Correct 1 ms 340 KB Output is correct
38 Correct 1 ms 340 KB Output is correct
39 Correct 1 ms 340 KB Output is correct
40 Correct 0 ms 212 KB Output is correct
41 Correct 6 ms 1108 KB Output is correct
42 Correct 7 ms 1108 KB Output is correct
43 Correct 7 ms 1108 KB Output is correct
44 Correct 6 ms 1156 KB Output is correct
45 Correct 7 ms 1136 KB Output is correct
46 Correct 7 ms 1108 KB Output is correct
47 Correct 8 ms 1156 KB Output is correct
48 Correct 8 ms 724 KB Output is correct
49 Correct 4 ms 568 KB Output is correct
50 Correct 1 ms 212 KB Output is correct
51 Correct 259 ms 13444 KB Output is correct
52 Correct 245 ms 13308 KB Output is correct
53 Correct 262 ms 13340 KB Output is correct
54 Correct 282 ms 13376 KB Output is correct
55 Correct 301 ms 13312 KB Output is correct
56 Correct 238 ms 13212 KB Output is correct
57 Correct 269 ms 13272 KB Output is correct
58 Correct 163 ms 13304 KB Output is correct
59 Correct 154 ms 13236 KB Output is correct
60 Correct 1 ms 212 KB Output is correct
61 Correct 485 ms 26188 KB Output is correct
62 Correct 565 ms 26060 KB Output is correct
63 Correct 494 ms 26388 KB Output is correct
64 Correct 518 ms 26148 KB Output is correct
65 Correct 547 ms 26148 KB Output is correct
66 Correct 503 ms 26264 KB Output is correct
67 Correct 539 ms 26152 KB Output is correct
68 Correct 414 ms 17088 KB Output is correct
69 Correct 319 ms 15500 KB Output is correct
70 Correct 1 ms 212 KB Output is correct