mirror of
https://git.sb/baoshuo/OI-codes.git
synced 2025-02-18 23:26:48 +00:00
parent
816fad5a7f
commit
1b0edafd84
@ -1,16 +1,15 @@
|
|||||||
#include <cstring>
|
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
|
#include <set>
|
||||||
|
|
||||||
using std::cin;
|
using std::cin;
|
||||||
using std::cout;
|
using std::cout;
|
||||||
using std::endl;
|
using std::endl;
|
||||||
|
|
||||||
const int N = 500005;
|
const int N = 500005,
|
||||||
const int P = 505;
|
P = 505;
|
||||||
|
|
||||||
int n, m, l, r, p, a[N];
|
int n, m, l, r, p, a[N];
|
||||||
long long sum[N];
|
long long sum[N];
|
||||||
bool vis[P];
|
|
||||||
|
|
||||||
int main() {
|
int main() {
|
||||||
cin >> n >> m;
|
cin >> n >> m;
|
||||||
@ -19,22 +18,18 @@ int main() {
|
|||||||
}
|
}
|
||||||
while (m--) {
|
while (m--) {
|
||||||
long long ans = 0x3f3f3f3f;
|
long long ans = 0x3f3f3f3f;
|
||||||
memset(vis, 0x00, sizeof(vis));
|
|
||||||
vis[0] = true;
|
|
||||||
cin >> l >> r >> p;
|
cin >> l >> r >> p;
|
||||||
if (r - l >= p) {
|
if (r - l >= p) {
|
||||||
cout << 0 << endl;
|
cout << 0 << endl;
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
std::set<long long> s;
|
||||||
|
s.insert(0);
|
||||||
sum[l - 1] = 0;
|
sum[l - 1] = 0;
|
||||||
for (int i = l; i <= r; i++) {
|
for (int i = l; i <= r; i++) {
|
||||||
sum[i] = (sum[i - 1] + a[i]) % p;
|
sum[i] = (sum[i - 1] + a[i]) % p;
|
||||||
for (int j = sum[i]; j >= 0; j--) {
|
ans = std::min(ans, sum[i] - *(--s.upper_bound(sum[i])));
|
||||||
if (vis[j]) {
|
s.insert(sum[i]);
|
||||||
ans = std::min(ans, sum[i] - j);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
vis[sum[i]] = true;
|
|
||||||
}
|
}
|
||||||
cout << ans << endl;
|
cout << ans << endl;
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user