0
1
mirror of https://git.sb/baoshuo/OI-codes.git synced 2024-11-27 13:56:26 +00:00

#1230. [常中20180903 T2] 小奇的数列

https://sjzezoj.com/submission/47732
This commit is contained in:
Baoshuo Ren 2022-01-21 09:08:59 +08:00
parent 816fad5a7f
commit 1b0edafd84
Signed by: baoshuo
GPG Key ID: 70F90A673FB1AB68

View File

@ -1,16 +1,15 @@
#include <cstring>
#include <iostream>
#include <set>
using std::cin;
using std::cout;
using std::endl;
const int N = 500005;
const int P = 505;
const int N = 500005,
P = 505;
int n, m, l, r, p, a[N];
long long sum[N];
bool vis[P];
int main() {
cin >> n >> m;
@ -19,22 +18,18 @@ int main() {
}
while (m--) {
long long ans = 0x3f3f3f3f;
memset(vis, 0x00, sizeof(vis));
vis[0] = true;
cin >> l >> r >> p;
if (r - l >= p) {
cout << 0 << endl;
continue;
}
std::set<long long> s;
s.insert(0);
sum[l - 1] = 0;
for (int i = l; i <= r; i++) {
sum[i] = (sum[i - 1] + a[i]) % p;
for (int j = sum[i]; j >= 0; j--) {
if (vis[j]) {
ans = std::min(ans, sum[i] - j);
}
}
vis[sum[i]] = true;
ans = std::min(ans, sum[i] - *(--s.upper_bound(sum[i])));
s.insert(sum[i]);
}
cout << ans << endl;
}