Submission #631362

# Submission time Handle Problem Language Result Execution time Memory
631362 2022-08-18T03:46:11 Z Spade1 Sails (IOI07_sails) C++14
60 / 100
100 ms 2580 KB
#include<bits/stdc++.h>
#define pii pair<int, int>
#define pll pair<long long, long long>
#define ll long long
#define ld long double
#define st first
#define nd second
#define pb push_back
#define INF INT_MAX
using namespace std;

const int N = 1e5 + 10;
pii s[N];
int fw[N];

int get(int i) {
    int ret = 0;
    for (; i > 0; i -= i&-i) {
        ret += fw[i];
    }
    return ret;
}

void add(int i, int val) {
    for (; i < N; i += i&-i) {
        fw[i] += val;
    }
}

int findl(int x) {
    int l = 1, r = x;
    int target = get(x);
    while (l < r) {
        int mid = (l+r)/2;
        if (get(mid) == target) r = mid;
        else l = mid + 1;
    }
    return l;
}

int findr(int x, int fr) {
    int l = x, r = fr;
    int target = get(x);
    while (l < r) {
        int mid = ceil(1.0*(l+r)/2);
        if (get(mid) == target) l = mid;
        else r = mid - 1;
    }
    return l;
}

void solve() {
    int n; cin >> n;
    for (int i = 1; i <= n; ++i) {
        cin >> s[i].st >> s[i].nd;
    }
    sort(s+1, s+n+1);
    for (int i = 1; i <= n; ++i) {
        int l = s[i].st - s[i].nd + 1, r = s[i].st;
        int lb = findl(l);
        int rb = findr(l, r);
        if (l == lb) {
            add(l, 1);
            add(r+1, -1);
        }
        else {
            add(rb+1, 1);
            add(r+1, -1);
            add(lb, 1);
            add(lb + (s[i].nd - (r - rb)), -1);
        }
    }

    ll sum = 0;
    for (int i = 1; i <= n; ++i) {
        int cur = get(i);
        sum += cur*(cur-1)/2;
    }
    cout << sum << '\n';
}

int main() {
    ios_base::sync_with_stdio(0); cin.tie(NULL);
    int t = 1;
//    cin >> t;
    while (t--) {
        solve();
    }
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 0 ms 340 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 0 ms 340 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 464 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 8 ms 468 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 26 ms 984 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 45 ms 1448 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 83 ms 2152 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 77 ms 2432 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 100 ms 2580 KB Output is correct
2 Correct 69 ms 2252 KB Output is correct