結果
| 問題 |
No.2974 関数の芽
|
| コンテスト | |
| ユーザー |
SSRS
|
| 提出日時 | 2024-11-29 22:13:49 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 550 ms / 2,000 ms |
| コード長 | 3,269 bytes |
| コンパイル時間 | 2,548 ms |
| コンパイル使用メモリ | 212,408 KB |
| 最終ジャッジ日時 | 2025-02-26 09:18:40 |
|
ジャッジサーバーID (参考情報) |
judge4 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 24 |
ソースコード
#include <bits/stdc++.h>
using namespace std;
struct dual_segment_tree{
int N;
vector<long long> ST;
dual_segment_tree(int n){
N = 1;
while (N < n){
N *= 2;
}
ST.resize(N * 2 - 1, 0);
}
void range_add(int L, int R, long long x, int i, int l, int r){
if (r <= L || R <= l){
} else if (L <= l && r <= R){
ST[i] += x;
} else {
int m = (l + r) / 2;
range_add(L, R, x, i * 2 + 1, l, m);
range_add(L, R, x, i * 2 + 2, m, r);
}
}
void range_add(int L, int R, long long x){
range_add(L, R, x, 0, 0, N);
}
long long operator [](int k){
k += N - 1;
long long ans = ST[k];
while (k > 0){
k = (k - 1) / 2;
ans += ST[k];
}
return ans;
}
};
int main(){
int Q;
cin >> Q;
vector<int> K(Q), L(Q), M(Q), N(Q), X(Q);
for (int i = 0; i < Q; i++){
cin >> K[i] >> L[i] >> M[i] >> N[i] >> X[i];
}
vector<int> X2 = X;
sort(X2.begin(), X2.end());
X2.erase(unique(X2.begin(), X2.end()), X2.end());
int cnt = X2.size();
dual_segment_tree ST_A(cnt), ST_B(cnt), ST_L(cnt), ST_R(cnt);
for (int i = 0; i < Q; i++){
if (K[i] > 0){
int pl = partition_point(X2.begin(), X2.end(), [&](long long x){
return K[i] * x + L[i] < 0;
}) - X2.begin();
int pr = partition_point(X2.begin(), X2.end(), [&](long long x){
return K[i] * x + L[i] <= 0;
}) - X2.begin();
ST_A.range_add(pr, cnt, K[i]);
ST_B.range_add(pr, cnt, L[i]);
ST_L.range_add(pr, cnt, K[i]);
ST_R.range_add(pl, cnt, K[i]);
} else if (K[i] < 0){
int pl = partition_point(X2.begin(), X2.end(), [&](long long x){
return K[i] * x + L[i] > 0;
}) - X2.begin();
int pr = partition_point(X2.begin(), X2.end(), [&](long long x){
return K[i] * x + L[i] >= 0;
}) - X2.begin();
ST_A.range_add(0, pr, K[i]);
ST_B.range_add(0, pr, L[i]);
ST_L.range_add(0, pr, K[i]);
ST_R.range_add(0, pl, K[i]);
} else {
ST_B.range_add(0, cnt, max(L[i], 0));
}
if (M[i] > 0){
int pl = partition_point(X2.begin(), X2.end(), [&](long long x){
return M[i] * x + N[i] < 0;
}) - X2.begin();
int pr = partition_point(X2.begin(), X2.end(), [&](long long x){
return M[i] * x + N[i] <= 0;
}) - X2.begin();
ST_A.range_add(pr, cnt, -M[i]);
ST_B.range_add(pr, cnt, -N[i]);
ST_L.range_add(pr, cnt, -M[i]);
ST_R.range_add(pl, cnt, -M[i]);
} else if (M[i] < 0){
int pl = partition_point(X2.begin(), X2.end(), [&](long long x){
return M[i] * x + N[i] > 0;
}) - X2.begin();
int pr = partition_point(X2.begin(), X2.end(), [&](long long x){
return M[i] * x + N[i] >= 0;
}) - X2.begin();
ST_A.range_add(0, pr, -M[i]);
ST_B.range_add(0, pr, -N[i]);
ST_L.range_add(0, pr, -M[i]);
ST_R.range_add(0, pl, -M[i]);
} else {
ST_B.range_add(0, cnt, -max(N[i], 0));
}
int p = lower_bound(X2.begin(), X2.end(), X[i]) - X2.begin();
__int128_t y = (__int128_t) ST_A[p] * X[i] + ST_B[p];
long long l = ST_L[p];
long long r = ST_R[p];
if (y == 0 && l == 0 && r == 0){
cout << "Yes" << endl;
} else {
cout << "No" << endl;
}
}
}
SSRS