Submission #655813

# Submission time Handle Problem Language Result Execution time Memory
655813 2022-11-05T15:47:07 Z Do_you_copy San (COCI17_san) C++17
0 / 120
311 ms 32552 KB
/*
    Procrastination is the art of keeping up with yesterday
*/
#include <bits/stdc++.h>
#define pb push_back
#define fi first
#define se second
#define faster ios_base::sync_with_stdio(0); cin.tie(0);
#define int long long
using namespace std;
using ll = long long;
using ld = long double;
using pii = pair <int, int>;
using pll = pair <ll, ll>;
mt19937_64 Rand(chrono::steady_clock::now().time_since_epoch().count());
const int maxN = 2e6 + 1;
//const int Mod = 1e9 + 7;
const int inf = 0x3f3f3f3f;
ll n, k;
ll dp[maxN];
vector <pll> S, T;
int last;
ll sum;
vector <ll> node;
int bit[maxN];
int a[maxN], b[maxN];
void update(int x, int val){
    for (; x <= node.size(); x += x & -x){
        bit[x] += val;
    }
}

int get(int x){
    int res = 0;
    for (; x; x -= x & -x){
        res += bit[x];
    }
    return res;
}

void attempt(int pos, int r, bool ok){
    if (pos > r){
        if (!ok) return;
        S.pb({last, sum});
        return;
    }
    int tem = last;
    attempt(pos + 1, r, ok);
    last = a[pos];
    sum += b[pos];
    attempt(pos + 1, r, tem <= a[pos]);
    sum -= b[pos];
    last = tem;
}

void attempt1(int pos, int l, bool ok){
    if (pos < l){
        if (!ok) return;
        T.pb({last, sum});
        node.pb(-sum);
        return;
    }
    int tem = last;
    attempt1(pos - 1, l, ok);
    last = a[pos];
    sum += b[pos];
    attempt1(pos - 1, l, ok & (tem >= a[pos]));
    sum -= b[pos];
    last = tem;
}

void Init(){
    cin >> n >> k;
    for (int i = 1; i <= n; ++i){
        cin >> a[i] >> b[i];
    }
    attempt(1, n / 2, 1);
    last = inf;
    attempt1(n, n / 2 + 1, 1);
    sort(S.begin(), S.end());
    sort(T.begin(), T.end());
    sort(node.begin(), node.end());
    node.resize(unique(node.begin(), node.end()) - node.begin());
    for (auto i: T){
        int p = upper_bound(node.begin(), node.end(), -i.se) - node.begin();
        update(p, 1);
        //cerr << i.se << "\n";
    }
    int j = 0;
    ll ans = 0;
    for (auto i: S){
        while (j < T.size() && i.fi > T[j].fi){
            int p = upper_bound(node.begin(), node.end(), -T[j].se) - node.begin();
            update(p, -1);
            ++j;
        }
        int p = upper_bound(node.begin(), node.end(), i.se - k) - node.begin();
        ans += get(p);
    }
    cout << ans;

}

#define debug
#define taskname "test"
signed main(){
    faster
    if (fopen(taskname".inp", "r")){
        freopen(taskname".inp", "r", stdin);
        freopen(taskname".out", "w", stdout);
    }
    int tt = 1;
    //cin >> tt;
    while (tt--){
        Init();
    }
    if (fopen("timeout.txt", "r")){
        ofstream timeout("timeout.txt");
        timeout << signed(double(clock()) / CLOCKS_PER_SEC * 1000);
        timeout.close();
        #ifndef debug
        cerr << "Time elapsed: " << signed(double(clock()) / CLOCKS_PER_SEC * 1000) << "ms\n";
        #endif // debug
    }
}

Compilation message

san.cpp: In function 'void update(long long int, long long int)':
san.cpp:28:14: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   28 |     for (; x <= node.size(); x += x & -x){
      |            ~~^~~~~~~~~~~~~~
san.cpp: In function 'void Init()':
san.cpp:92:18: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<std::pair<long long int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   92 |         while (j < T.size() && i.fi > T[j].fi){
      |                ~~^~~~~~~~~~
san.cpp: In function 'int main()':
san.cpp:109:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
  109 |         freopen(taskname".inp", "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~
san.cpp:110:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
  110 |         freopen(taskname".out", "w", stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Incorrect 0 ms 340 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Incorrect 1 ms 336 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 20 ms 3416 KB Output is correct
2 Incorrect 8 ms 1492 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 66 ms 10124 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 311 ms 32552 KB Output isn't correct
2 Halted 0 ms 0 KB -