답안 #655715

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
655715 2022-11-05T11:09:43 Z Do_you_copy San (COCI17_san) C++17
0 / 120
433 ms 44864 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);

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, 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);
    }
    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(int, int)':
san.cpp:28:14: warning: comparison of integer expressions of different signedness: '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:91:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<long long int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   91 |         while (j < T.size() && i.fi > T[j].fi){
      |                ~~^~~~~~~~~~
san.cpp: In function 'int main()':
san.cpp:108:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
  108 |         freopen(taskname".inp", "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~
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".out", "w", stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 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 -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 340 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 19 ms 3124 KB Output is correct
2 Incorrect 22 ms 3160 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 97 ms 11904 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 433 ms 44864 KB Output isn't correct
2 Halted 0 ms 0 KB -