結果
問題 | No.728 ギブ and テイク |
ユーザー | ats5515 |
提出日時 | 2018-08-24 22:06:47 |
言語 | C++11 (gcc 11.4.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 2,966 bytes |
コンパイル時間 | 978 ms |
コンパイル使用メモリ | 87,260 KB |
実行使用メモリ | 16,512 KB |
最終ジャッジ日時 | 2024-06-23 07:31:06 |
合計ジャッジ時間 | 5,218 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge1 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 16 ms
12,032 KB |
testcase_01 | AC | 15 ms
12,032 KB |
testcase_02 | AC | 16 ms
12,032 KB |
testcase_03 | AC | 15 ms
12,032 KB |
testcase_04 | AC | 15 ms
12,032 KB |
testcase_05 | AC | 15 ms
12,032 KB |
testcase_06 | AC | 15 ms
12,032 KB |
testcase_07 | AC | 15 ms
12,160 KB |
testcase_08 | AC | 15 ms
12,032 KB |
testcase_09 | AC | 16 ms
12,160 KB |
testcase_10 | AC | 16 ms
12,032 KB |
testcase_11 | AC | 16 ms
12,160 KB |
testcase_12 | AC | 19 ms
12,160 KB |
testcase_13 | AC | 34 ms
12,288 KB |
testcase_14 | AC | 43 ms
12,544 KB |
testcase_15 | AC | 26 ms
12,160 KB |
testcase_16 | AC | 39 ms
12,416 KB |
testcase_17 | AC | 37 ms
12,408 KB |
testcase_18 | WA | - |
testcase_19 | WA | - |
testcase_20 | WA | - |
testcase_21 | WA | - |
testcase_22 | WA | - |
testcase_23 | AC | 72 ms
12,672 KB |
testcase_24 | WA | - |
testcase_25 | WA | - |
testcase_26 | AC | 102 ms
13,312 KB |
testcase_27 | WA | - |
testcase_28 | WA | - |
testcase_29 | AC | 17 ms
12,160 KB |
testcase_30 | AC | 16 ms
12,032 KB |
testcase_31 | AC | 16 ms
12,160 KB |
testcase_32 | AC | 15 ms
12,032 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 = 31; wavelet<int, _N, D> a; int ri[300100]; signed main() { cin.tie(0); ios::sync_with_stdio(false); 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<int, _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)2e9 + 5); } cout << res << endl; }