题解:P9789 [ROIR 2020 Day 2] ATM
fight_for_humanity · · 题解
题目的关键:"每次选取一个选取后发给用户的总金额不超过
考虑
我们现在考虑怎么应对询问。我们在上面预处理的过程中只是挖掉了
时间复杂度:
CODE
#include<bits/stdc++.h>
using namespace std;
#define int long long
const int N = 2e5 + 10;
const int inf = 0x3f3f3f3f3f3f3f3f;
int n,q,a[N],x[N],y[N];
template <typename T>
inline void read(T &x){
x = 0;
static char c;
static bool f;
c = getchar(), f = 0;
while(c<'0'||c>'9'){ if(c == '-')f = 1; c = getchar(); }
while('0'<=c&&c<='9')x = (x << 3) + (x << 1) + (c ^ 48), c = getchar();
x = f ? -x : x;
}
signed main(){
read(n);
for(int i = 1;i<=n;++i)read(a[i]);
for(int i = 1;i<n;++i){
int tmp = (a[i+1] - x[i] - 1) / a[i];
x[i+1] = x[i] + tmp * a[i], y[i+1] = y[i] + tmp;
}
read(q);
int val; while(q--){
read(val);
int cur = upper_bound(a+1,a+n+1,val)-a-1;
int it = (val - x[cur]) / a[cur];
printf("%lld %lld\n",x[cur] + it * a[cur], it + y[cur]);
}
return 0;
}