Submission #655815

#TimeUsernameProblemLanguageResultExecution timeMemory
655815Do_you_copySan (COCI17_san)C++17
120 / 120
249 ms29216 KiB
/* 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, ok & (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 (stderr)

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 timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...