Submission #670099

# Submission time Handle Problem Language Result Execution time Memory
670099 2022-12-08T06:20:44 Z raypeng1729 Sails (IOI07_sails) C++17
0 / 100
1000 ms 5324 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], mx = max(mx, b[i]);
    int st[mx + 2]{}, en[mx + 2]{};
    st[0] = 1, en[0] = n;
    BIT bit;
    for(int i = 0; i < n; i++){
        int ok = 0;
        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:28:13: warning: unused variable 'ok' [-Wunused-variable]
   28 |         int ok = 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 Execution timed out 1081 ms 1108 KB Time limit exceeded
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 1620 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 14 ms 2388 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 22 ms 3156 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 30 ms 4672 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 42 ms 5076 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 37 ms 5324 KB Output isn't correct
2 Halted 0 ms 0 KB -