Submission #441351

# Submission time Handle Problem Language Result Execution time Memory
441351 2021-07-05T04:42:32 Z SirCovidThe19th Sails (IOI07_sails) C++14
0 / 100
1000 ms 2868 KB
#include <bits/stdc++.h>
using namespace std;

const int mx = 1e5+5;

int n, bit[mx], nums[mx]; pair<int, int> vals[mx]; long long ans;

void upd(int l, int r, int val){
    for (; l <= n; l += l&(-l)) bit[l] += val;
    for (++r; r <= n; r += r&(-r)) bit[r] -= val;
}
int query(int i){
    int ret = 0;
    for (; i > 0; i -= i&(-i)) ret += bit[i];
    return ret;
}

int main(){ 
    cin >> n; iota(nums, nums+mx, 0);
    for (int i = 0; i < n; i++) cin >> vals[i].first >> vals[i].second;
    sort(vals, vals+n, greater<pair<int, int>>());
    for (int i = 0; i < n; i++){
        int H = vals[i].first, S = vals[i].second, L, F; 
        L = upper_bound(nums+1, nums+H+1, query(S), [](int val, int a){ return query(a) > val; })-nums-1;
        F = lower_bound(nums+1, nums+H+1, query(S), [](int a, int val){ return query(a) < val; })-nums;
        upd(1, F-1, 1); upd(L-(S-F), L, 1);
    }for (int i = 1; i < mx; i++){
        long long q = query(i); ans += (q*(q-1))/2;
    }cout<<ans;
}

# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 684 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 588 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 588 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 3 ms 588 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 1094 ms 716 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 1092 ms 844 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 41 ms 1328 KB Output isn't correct
# Verdict Execution time Memory Grader output
1 Incorrect 68 ms 1784 KB Output isn't correct
# Verdict Execution time Memory Grader output
1 Execution timed out 1093 ms 2372 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 1088 ms 2500 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 147 ms 2868 KB Output isn't correct
2 Halted 0 ms 0 KB -