Submission #114284

# Submission time Handle Problem Language Result Execution time Memory
114284 2019-05-31T17:02:03 Z popovicirobert Sails (IOI07_sails) C++14
100 / 100
99 ms 2748 KB
#include <bits/stdc++.h>
 
#define long long long
#define pii pair<int, int>
#define x first
#define y second
 
using namespace std;
 
const int N = 1e5+5;
 
int n;
vector<pii> vec;
long t[N];
 
void update(int x, long k) { for(int i = x; i < N; i += i & -i) t[i] += k; }
 
long query(int x, long ret = 0) { for(int i = x; i; i -= i & -i) ret += t[i]; return ret; }
 
int main() {
    scanf("%d", &n);
    for(int i = 1, a, b; i <= n; i++) scanf("%d %d", &a, &b), vec.emplace_back(a, b);
    sort(vec.begin(), vec.end());
    for(int i = 0, h, k; i < n; i++) {
        auto idx = [&](int x) {
            int l = 0, r = h;
            while(l < r) {
                int m = (l + r + 1) >> 1;
                if(query(m) >= x) l = m;
                else r = m-1;
            }
            return l;
        };
        tie(h, k) = vec[i];
        int up = idx(query(h - k + 1)), dw = idx(query(h - k + 1) + 1);
        update(up + 1, 1), update(h + 1, -1);
        update(dw + 1, 1), update(dw + 1 + (k - h + up), -1); 
    }
    long ans = 0;
    for(int i = 1; i < N; i++) {
        long now = query(i);
        ans += now * (now - 1) / 2;
    }
    printf("%lld\n", ans);
 
    return 0;
}

Compilation message

sails.cpp: In function 'int main()':
sails.cpp:21:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d", &n);
     ~~~~~^~~~~~~~~~
sails.cpp:22:61: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     for(int i = 1, a, b; i <= n; i++) scanf("%d %d", &a, &b), vec.emplace_back(a, b);
                                       ~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 3 ms 384 KB Output is correct
2 Correct 3 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 384 KB Output is correct
2 Correct 2 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 384 KB Output is correct
2 Correct 1 ms 512 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 384 KB Output is correct
2 Correct 4 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 384 KB Output is correct
2 Correct 4 ms 1152 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 13 ms 768 KB Output is correct
2 Correct 22 ms 768 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 20 ms 1012 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 46 ms 1244 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 88 ms 1932 KB Output is correct
2 Correct 76 ms 2748 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 76 ms 1904 KB Output is correct
2 Correct 62 ms 2592 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 99 ms 1960 KB Output is correct
2 Correct 61 ms 2540 KB Output is correct