Submission #670100

# Submission time Handle Problem Language Result Execution time Memory
670100 2022-12-08T06:29:25 Z raypeng1729 Sails (IOI07_sails) C++17
0 / 100
41 ms 4296 KB
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define all(v) v.begin(), v.end()
const int N = 1e5 + 2, INF = 1e9 + 1, MOD = 1e9 + 7, K = __lg(N) + 1;
struct BIT{
    int n;
    vector<int> v;
    BIT(){v.assign(N, 0);}
    void add(int i, int x){
        for(; i < N; i += i & (-i)) v[i] += x;
    }
    int qry(int i){
        int ret = 0;
        for(; i > 0; i -= i & (-i)) ret += v[i];
        return ret;
    }
};
signed main(){
    ios::sync_with_stdio(false); cin.tie(0);
    int n; cin >> n;
    int a[n], b[n], mx = 0;
    for(int i = 0; i < n; i++) cin >> a[i] >> b[i];
    int st[n + 2]{}, en[n + 2]{};
    st[0] = 1, en[0] = n;
    BIT bit;
    for(int i = 0; i < n; i++){
        while(b[i]){
            int x = bit.qry(a[i]);
            int y = min(b[i], a[i] - st[x] + 1); b[i] -= y;
            bit.add(st[x], 1), bit.add(st[x] + y, -1);
            if(st[x + 1] == 0) st[x + 1] = st[x];
            en[x + 1] = max(en[x + 1], st[x] + y - 1);
            st[x] = st[x] + y;
        }
    }
    int ans = 0;
    for(int i = 0; i <= n; i++){
        int x = bit.qry(i);
        ans += x * (x - 1) / 2;
    }
    cout << ans;
}

Compilation message

sails.cpp: In function 'int main()':
sails.cpp:22:21: warning: unused variable 'mx' [-Wunused-variable]
   22 |     int a[n], b[n], mx = 0;
      |                     ^~
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 1108 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 1108 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 1108 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 1108 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 1108 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 4 ms 1364 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 16 ms 2132 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 19 ms 2764 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 28 ms 3532 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 41 ms 3924 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 32 ms 4296 KB Output isn't correct
2 Halted 0 ms 0 KB -