結果
| 問題 |
No.2359 A in S ?
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2023-06-23 22:41:29 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
RE
|
| 実行時間 | - |
| コード長 | 2,199 bytes |
| コンパイル時間 | 1,604 ms |
| コンパイル使用メモリ | 140,592 KB |
| 最終ジャッジ日時 | 2025-02-15 01:21:27 |
|
ジャッジサーバーID (参考情報) |
judge5 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 2 |
| other | AC * 12 WA * 1 RE * 5 |
ソースコード
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <cmath>
#include <iomanip>
#include <stack>
#include <queue>
#include <numeric>
#include <map>
#include <unordered_map>
#include <set>
#include <fstream>
#include <chrono>
#include <random>
#include <bitset>
//#include <atcoder/all>
#define rep(i,n) for(int i=0;i<(n);i++)
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define sz(x) ((int)(x).size())
#define pb push_back
using ll = long long;
using namespace std;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
ll gcd(ll a, ll b) {return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b) {return a/gcd(a,b)*b;}
int main(){
ios::sync_with_stdio(false);
cin.tie(nullptr);
int N,M; cin >> N >> M;
int mx = 100010;
vector<int> A(mx,0);
vector<vector<int>> Q(N);
int B = 320;
vector<vector<vector<int>>> qv(B,vector<vector<int>>(B));
vector<vector<vector<int>>> qa(B,vector<vector<int>>(B));
rep(i,B){
rep(j,B){
qv[i][j].pb(0);
qv[i][j].pb(1<<30);
}
}
rep(i,N){
int l,r,x,y; cin >> l >> r >> x >> y;
Q[i] = {l,r,x,y};
if(y>=B){
for(ll a=x;a<mx;a+=y){
if(l<=a&&a<=r) A[a]++;
}
}
else{
qv[x][y].pb(l);
qv[x][y].pb(r+1);
}
}
rep(i,B){
rep(j,B){
sort(all(qv[i][j]));
qv[i][j].erase(unique(qv[i][j].begin(),qv[i][j].end()),qv[i][j].end());
qa[i][j].assign(sz(qv[i][j]),0);
}
}
rep(i,N){
int l=Q[i][0], r=Q[i][1], x=Q[i][2], y=Q[i][3];
if(y<B){
int i1 = lower_bound(all(qv[x][y]),l)-qv[x][y].begin();
int i2 = lower_bound(all(qv[x][y]),r+1)-qv[x][y].begin();
qa[x][y][i1]++;
qa[x][y][i2]--;
}
}
rep(i,B){
rep(j,B){
rep(k,sz(qa[i][j])-1) qa[i][j][k+1] += qa[i][j][k];
}
}
while(M--){
int a; cin >> a;
int ans = A[a];
for(int x=1;x<B;x++){
int y = a % x;
int idx = prev(upper_bound(all(qv[x][y]),a))-qv[x][y].begin();
ans += qa[x][y][idx];
}
cout << ans << '\n';
}
return 0;
};