結果
問題 | No.728 ギブ and テイク |
ユーザー | ats5515 |
提出日時 | 2018-08-24 22:08:46 |
言語 | C++11 (gcc 11.4.0) |
結果 |
AC
|
実行時間 | 407 ms / 3,000 ms |
コード長 | 3,027 bytes |
コンパイル時間 | 740 ms |
コンパイル使用メモリ | 87,156 KB |
実行使用メモリ | 26,112 KB |
最終ジャッジ日時 | 2024-06-23 07:35:17 |
合計ジャッジ時間 | 5,891 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge1 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 21 ms
16,896 KB |
testcase_01 | AC | 23 ms
16,896 KB |
testcase_02 | AC | 23 ms
16,896 KB |
testcase_03 | AC | 23 ms
17,024 KB |
testcase_04 | AC | 23 ms
16,896 KB |
testcase_05 | AC | 22 ms
16,896 KB |
testcase_06 | AC | 23 ms
16,896 KB |
testcase_07 | AC | 23 ms
16,896 KB |
testcase_08 | AC | 23 ms
16,896 KB |
testcase_09 | AC | 23 ms
16,768 KB |
testcase_10 | AC | 24 ms
17,024 KB |
testcase_11 | AC | 22 ms
17,024 KB |
testcase_12 | AC | 21 ms
16,896 KB |
testcase_13 | AC | 47 ms
17,152 KB |
testcase_14 | AC | 61 ms
17,664 KB |
testcase_15 | AC | 39 ms
17,152 KB |
testcase_16 | AC | 57 ms
17,408 KB |
testcase_17 | AC | 53 ms
17,408 KB |
testcase_18 | AC | 294 ms
23,296 KB |
testcase_19 | AC | 301 ms
23,680 KB |
testcase_20 | AC | 352 ms
24,832 KB |
testcase_21 | AC | 326 ms
24,064 KB |
testcase_22 | AC | 144 ms
19,584 KB |
testcase_23 | AC | 90 ms
18,560 KB |
testcase_24 | AC | 230 ms
22,144 KB |
testcase_25 | AC | 230 ms
22,144 KB |
testcase_26 | AC | 127 ms
19,584 KB |
testcase_27 | AC | 407 ms
25,984 KB |
testcase_28 | AC | 247 ms
26,112 KB |
testcase_29 | AC | 23 ms
17,024 KB |
testcase_30 | AC | 22 ms
17,024 KB |
testcase_31 | AC | 22 ms
16,768 KB |
testcase_32 | AC | 21 ms
16,896 KB |
ソースコード
#include <iostream> #include <vector> #include <map> #include <set> #include <queue> #include <string> #include <iomanip> #include <algorithm> #include <cmath> #include <stdio.h> #include <cstdint> #include <cstring> using namespace std; #define repi(i,a,b) for(int i = (int)(a); i < (int)(b); i++) #define rep(i,n) repi(i,0,n) template<int N> class FID { static const int bucket = 512, block = 16; static char popcount[]; int n, B[N / bucket + 10]; unsigned short bs[N / block + 10], b[N / block + 10]; public: FID() {} FID(int n, bool s[]) : n(n) { if (!popcount[1]) for (int i = 0; i < (1 << block); i++) popcount[i] = __builtin_popcount(i); bs[0] = B[0] = b[0] = 0; for (int i = 0; i < n; i++) { if (i%block == 0) { bs[i / block + 1] = 0; if (i%bucket == 0) { B[i / bucket + 1] = B[i / bucket]; b[i / block + 1] = b[i / block] = 0; } else b[i / block + 1] = b[i / block]; } bs[i / block] |= short(s[i]) << (i%block); b[i / block + 1] += s[i]; B[i / bucket + 1] += s[i]; } if (n%bucket == 0) b[n / block] = 0; } int count(bool val, int r) { return val ? B[r / bucket] + b[r / block] + popcount[bs[r / block] & ((1 << (r%block)) - 1)] : r - count(1, r); } int count(bool val, int l, int r) { return count(val, r) - count(val, l); } }; template<int N> char FID<N>::popcount[1 << FID<N>::block]; template<class T, int N, int D> class wavelet { int n, zs[D]; FID<N> dat[D]; int freq_dfs(int d, int l, int r, T val, T a, T b) { if (l >= r or val >= b) return 0; if (d == D) return a <= val ? r - l : 0; T nv = 1LL << (D - d - 1) | val, nnv = ((1ULL << (D - d - 1)) - 1) | nv; if (nnv < a) return 0; if (a <= val and nnv < b) return r - l; int lc = dat[d].count(1, l), rc = dat[d].count(1, r); return freq_dfs(d + 1, l - lc, r - rc, val, a, b) + freq_dfs(d + 1, lc + zs[d], rc + zs[d], nv, a, b); } public: wavelet() {} wavelet(int n, T seq[]) : n(n) { T f[N], l[N], r[N]; bool b[N]; memcpy(f, seq, sizeof(T)*n); for (int d = 0; d < D; d++) { int lh = 0, rh = 0; for (int i = 0; i < n; i++) { bool k = (f[i] >> (D - d - 1)) & 1; if (k) r[rh++] = f[i]; else l[lh++] = f[i]; b[i] = k; } dat[d] = FID<N>(n, b); zs[d] = lh; swap(l, f); memcpy(f + lh, r, rh * sizeof(T)); } } int freq(int l, int r, T a, T b) { return freq_dfs(0, l, r, 0, a, b); } }; const int _N = 300100, D = 40; wavelet<long long, _N, D> a; #define int long long int ri[300100]; signed main() { cin.tie(0); ios::sync_with_stdio(false); cerr << (int)3e9 << endl; int N; cin >> N; vector<int> A(N); vector<int> L(N); vector<int> R(N); int res = 0; for (int i = 0; i < N; i++) { cin >> A[i]; } for (int i = 0; i < N; i++) { cin >> L[i] >> R[i]; } for (int i = 0; i < N; i++) { ri[i] = A[i] + R[i]; } a = wavelet<long long, _N, D>(N, ri); for (int i = 0; i < N; i++) { int le = lower_bound(A.begin(), A.end(), A[i] - L[i]) - A.begin(); res += a.freq(le, i, A[i], (int)3e9 + 5); } cout << res << endl; }