結果
問題 | No.2359 A in S ? |
ユーザー |
|
提出日時 | 2023-06-23 22:46:48 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 689 ms / 2,000 ms |
コード長 | 1,194 bytes |
コンパイル時間 | 2,295 ms |
コンパイル使用メモリ | 209,272 KB |
最終ジャッジ日時 | 2025-02-15 01:25:31 |
ジャッジサーバーID (参考情報) |
judge5 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 2 |
other | AC * 18 |
ソースコード
#include <bits/stdc++.h>using namespace std;int gcd(int a, int b) {return (a ? gcd(a, b % a) : b);}int main () {int N, M;cin >> N >> M;std::vector<tuple<int, int, int, int>> X;vector<int> cnt1(100010, 0);const int H = 300;vector<vector<vector<pair<int, int>>>> cnt2(H, vector<vector<pair<int, int>>>(H));for (int i = 0; i < N; i ++) {int l, r, x, y;cin >> l >> r >> x >> y;if (x < H) {cnt2[x][y].emplace_back(l, 1);cnt2[x][y].emplace_back(r + 1, -1);} else {for (int j = 0; j * x + y <= r; j ++) {if (j * x + y >= l) cnt1[j * x + y] ++;}}}for (int i = 1; i < H; i ++) {for (int j = 0; j < i; j ++) {auto& a = cnt2[i][j];a.emplace_back(-1, 0);sort(a.begin(), a.end());for (int k = 1; k < a.size(); k ++) {a[k].second += a[k - 1].second;}}}while (M --) {int a;cin >> a;int ans = cnt1[a];/*for (auto [l, r, x, y] : X) {ans += (l <= a && a <= r && (a % x == y));}*/for (int i = 1; i < H; i ++) {auto pt = lower_bound(cnt2[i][a % i].begin(), cnt2[i][a % i].end(), make_pair(a + 1, -1));ans += prev(pt) -> second;}cout << ans << endl;}}