QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#150137 | #2308. 胖 | james1BadCreeper | 100 ✓ | 608ms | 58960kb | C++14 | 2.7kb | 2023-08-25 15:21:55 | 2023-08-25 15:21:58 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
typedef long long i64;
const i64 INF = 2e18;
int n, m, K;
struct Node {
int p, d;
bool operator< (const Node &a) const {
return p < a.p;
}
} a[200005];
i64 dis[200005];
namespace ST {
int lg[200005]; i64 f[18][200005], g[18][200005];
i64 query(int op, int l, int r) {
l = max(1, l); r = min(r, n);
Node tmp = {l, 0}; l = lower_bound(a + 1, a + K + 1, tmp) - a;
tmp = {r, 0}; r = upper_bound(a + 1, a + K + 1, tmp) - (a + 1);
if (l > r) return INF;
int k = lg[r - l + 1];
if (op == 1) return min(f[k][l], f[k][r - (1 << k) + 1]);
return min(g[k][l], g[k][r - (1 << k) + 1]);
}
void init(void) {
for (int i = 2; i <= K; ++i) lg[i] = lg[i >> 1] + 1;
for (int i = 1; i <= K; ++i)
f[0][i] = a[i].d - dis[a[i].p], //
g[0][i] = a[i].d + dis[a[i].p]; //
for (int i = 1; i <= lg[K]; ++i)
for (int j = 1; j + (1 << i) - 1 <= K; ++j)
f[i][j] = min(f[i - 1][j], f[i - 1][j + (1 << i - 1)]),
g[i][j] = min(g[i - 1][j], g[i - 1][j + (1 << i - 1)]);
}
}
using namespace ST;
bool checkl(int p, int x) { // p 更新到 x,x < p
if (p == x) return 1; int d = abs(p - x);
i64 t1 = query(1, x - d, x) + dis[x];
i64 t2 = query(2, x, x + d - 1) - dis[x];
i64 now = query(2, p, p) - dis[x];
return t1 > now && t2 > now;
}
int calcl(int p) {
int L = 0, R = p + 1;
while (L + 1 != R) {
int mid = L + R >> 1;
if (checkl(p, mid)) R = mid;
else L = mid;
}
return R;
}
bool checkr(int p, int x) { // 从 p 能否更新到 x,x > p
if (p == x) return 1; int d = abs(p - x);
i64 t1 = query(1, x - d + 1, x) + dis[x];
i64 t2 = query(2, x, x + d - 1) - dis[x]; // x + x - p - 1
i64 now = query(1, p, p) + dis[x];
if (t1 <= now || t2 <= now) return 0;
if (x + d <= n) return query(2, x + d, x + d) - dis[x] >= now; // 如果此时
return 1;
}
int calcr(int p) {
int L = p - 1, R = n + 1;
while (L + 1 != R) {
int mid = L + R >> 1;
if (checkr(p, mid)) L = mid;
else R = mid;
}
return L;
}
int main(void) {
scanf("%d%d", &n, &m);
for (int i = 2; i <= n; ++i) scanf("%lld", dis + i), dis[i] += dis[i - 1];
while (m--) {
scanf("%d", &K);
for (int i = 1; i <= K; ++i) scanf("%d%d", &a[i].p, &a[i].d);
sort(a + 1, a + K + 1); ST::init();
i64 ans = 0;
for (int i = 1; i <= K; ++i) ans += (calcr(a[i].p) - calcl(a[i].p) + 1);
printf("%lld\n", ans);
}
return 0;
}
详细
Test #1:
score: 10
Accepted
time: 22ms
memory: 24140kb
input:
1000 100 2 2 3 4 2 4 4 4 1 1 4 1 4 3 3 4 2 1 2 2 3 2 4 3 1 4 3 2 4 4 4 3 1 1 4 2 3 3 3 2 3 1 3 4 2 4 3 3 1 1 4 3 3 2 4 2 2 4 4 1 1 2 4 1 3 1 4 3 4 2 4 3 4 1 1 3 2 1 4 3 2 1 4 2 2 3 2 3 2 4 1 4 2 2 4 2 2 1 3 257799480 361327555 541424941 840754242 114131228 500635419 338541381 180792758 687484973 979...
output:
36662 1181 1264 1172 1192 1203 1182 1173 1189 1189 1194 1184 1119 1121 1239 1164 1203 1165 1213 1245 1100 1163 1273 1185 1189 1213 1148 1132 1136 1172 1179 1287 1310 1215 1203 1179 1161 1253 1183 1388 1207 1202 1123 1190 1116 1180 1190 1143 1166 1180 1117 1159 1155 1192 1194 1134 1146 1208 1162 1112...
result:
ok 100 lines
Test #2:
score: 10
Accepted
time: 13ms
memory: 26344kb
input:
1000 100 4 2 2 3 3 1 1 3 4 2 1 2 1 3 4 4 4 2 1 1 4 2 2 2 1 2 4 3 1 4 2 3 1 4 3 2 4 2 4 2 4 1 2 1 2 2 1 4 3 2 2 2 1 1 1 3 1 1 3 4 3 3 2 1 2 2 2 1 1 2 3 2 4 2 2 3 4 1 2 2 4 3 2 2 2 4 2 1 4 3 1 4 2 3 1 3 1 2 3 892053145 153851502 4844898 616783872 382955829 330111138 227619359 723153178 70982398 147722...
output:
21891 1304 1233 1188 1174 1192 1307 1198 1141 1174 1174 1209 1231 1155 1208 1279 1148 1169 1131 1221 1165 1197 1181 1212 1198 1218 1230 1130 1246 1124 1115 1184 1189 1155 1141 1121 1208 1112 1177 1161 1248 1159 1172 1163 1243 1184 1201 1204 1165 1159 1181 1185 1143 1157 1202 1184 1156 1148 1192 1358...
result:
ok 100 lines
Test #3:
score: 10
Accepted
time: 271ms
memory: 28200kb
input:
200000 41298 3 2 3 1 1 1 4 1 4 2 4 2 2 4 3 3 3 1 4 1 1 4 1 4 3 1 2 3 4 1 4 4 1 2 2 4 4 2 3 1 4 3 3 4 3 2 2 3 4 4 3 3 4 4 1 3 3 1 3 3 3 4 1 4 2 1 1 3 4 3 4 2 4 4 1 1 2 3 2 2 2 4 3 1 2 4 2 1 2 4 1 1 3 4 1 3 3 2 2 4 2 3 4 3 2 2 2 1 2 4 2 2 1 2 4 3 1 2 3 3 4 2 2 1 3 3 4 1 3 1 3 3 3 4 3 1 3 3 3 1 4 2 1 2...
output:
4798851 9197738 9397444 5598493 10197454 4598797 3599938 2800161 1601279 5198793 3799222 4398892 5398894 5198859 3399805 3599586 8597663 5998467 2000734 2800193 601781 601808 6398469 1801055 9797536 6598021 4998906 5998442 4399247 9597295 5998644 9597376 5198852 4798687 4598787 7197998 6398180 20005...
result:
ok 41298 lines
Test #4:
score: 10
Accepted
time: 279ms
memory: 26240kb
input:
200000 41303 3 3 3 3 1 3 1 4 4 1 3 2 1 3 1 2 2 4 2 3 3 2 4 1 3 2 2 3 1 4 3 2 4 1 2 1 1 2 4 4 2 2 4 1 1 3 1 3 4 1 4 1 3 2 2 2 2 2 3 4 1 3 1 1 1 2 1 4 2 1 2 2 3 3 1 3 4 4 4 4 1 4 4 2 3 3 2 1 3 1 2 1 1 3 4 3 3 2 2 4 3 3 3 4 2 4 2 3 2 1 4 3 1 4 2 3 2 2 4 2 1 4 2 3 2 3 4 2 2 2 3 3 2 4 1 2 1 3 3 2 2 2 2 1...
output:
8597554 4399118 602069 4599026 6798205 3599600 6398264 3599891 6598213 3199974 3199810 1001867 10997058 8597449 6198574 4998687 3399747 4199233 5598521 9797339 1001569 1201360 8197686 6797928 1001827 9397573 5998286 2200632 4199655 9397830 6798151 402060 5198542 2400960 3999249 3799555 7798164 59984...
result:
ok 41303 lines
Test #5:
score: 10
Accepted
time: 308ms
memory: 32492kb
input:
200000 23570 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1...
output:
799999 1999889 800024 600022 600082 2399851 2599848 1999871 1999864 600124 600070 2199868 600027 400066 1799894 600124 2199846 1599894 200146 1799879 999974 1599890 1199936 1399969 400058 600040 800063 600059 1599897 2799834 1799874 1599917 2199854 2999792 999963 400022 2399881 1799889 1599914 27998...
result:
ok 23570 lines
Test #6:
score: 10
Accepted
time: 302ms
memory: 28392kb
input:
200000 23570 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1...
output:
400015 400070 3399808 2199867 1599917 800008 400061 2199842 400100 200223 600057 2599858 999983 600077 1599896 3199794 1199953 1599899 200104 1999876 1799879 1399927 600065 1199939 200159 1999880 2199871 1799872 400062 1799898 999967 600082 200084 600096 799956 999991 1399916 1599905 400081 1799905 ...
result:
ok 23570 lines
Test #7:
score: 10
Accepted
time: 571ms
memory: 53724kb
input:
200000 20335 3 4 4 2 4 2 1 3 1 2 2 2 4 2 3 4 4 1 4 1 2 3 1 1 4 4 1 4 4 2 1 2 4 2 3 3 1 2 3 2 4 2 2 1 2 1 1 4 2 4 2 4 4 4 4 1 4 1 2 3 2 1 1 1 3 2 2 3 2 3 3 1 4 1 3 4 3 1 1 4 1 2 1 1 3 3 1 2 3 1 2 3 3 2 2 1 3 2 3 2 2 1 2 3 3 1 3 3 1 2 4 4 1 4 2 3 3 3 2 4 4 3 1 2 4 3 3 4 1 1 4 1 1 3 4 4 4 4 2 2 2 3 2 1...
output:
4138928975 4242989233 200078 399881 200057 200078 200069 399883 200082 200069 200079 200078 200082 200074 200071 200078 200067 200068 200068 200079 200077 200075 200087 200079 200079 200076 200092 200069 200075 200076 200074 200064 200066 200091 200071 200081 200069 200081 200069 200067 200082 20006...
result:
ok 20335 lines
Test #8:
score: 10
Accepted
time: 597ms
memory: 58960kb
input:
200000 20337 3 1 1 1 2 3 4 2 4 1 4 2 1 3 2 3 4 3 2 4 1 3 3 4 3 2 3 3 4 3 3 1 1 3 4 1 2 2 1 1 4 2 3 3 4 3 2 3 2 2 3 3 3 2 1 3 2 2 3 4 4 3 2 4 4 1 1 2 4 1 1 1 2 3 4 2 1 2 2 3 1 3 4 2 4 4 1 2 4 3 3 1 1 3 2 1 2 1 2 1 3 1 3 3 3 3 4 2 3 4 1 4 2 2 1 4 1 3 1 3 4 3 4 3 4 1 2 1 2 1 2 1 4 1 3 2 4 4 1 3 1 3 2 1...
output:
4283102892 4324420397 399873 200072 200080 200073 200085 200075 200081 200064 399857 200086 200072 399879 200065 399870 200068 399882 200077 399877 200081 399866 200083 200066 200072 200077 200079 200073 200081 200078 200069 200067 200075 200078 200060 200071 200064 399874 200054 200082 399870 20007...
result:
ok 20337 lines
Test #9:
score: 10
Accepted
time: 608ms
memory: 57260kb
input:
200000 20337 4 2 2 3 4 4 4 2 3 2 3 4 1 4 4 3 4 4 3 1 2 2 2 3 1 3 3 4 4 2 4 4 2 3 4 4 3 2 2 4 3 3 4 3 1 3 4 3 3 3 1 2 3 3 3 1 4 1 4 3 2 1 2 4 2 4 2 1 1 3 2 4 1 2 1 1 1 3 3 1 2 3 4 4 4 1 2 2 3 2 3 1 3 2 4 2 4 4 3 3 4 1 1 1 2 1 1 1 1 4 2 3 1 1 3 2 3 4 3 4 3 4 1 3 1 1 1 3 2 4 2 3 4 2 4 4 2 3 3 2 4 1 4 1...
output:
2454458545 3212402101 399868 200079 200068 200059 399875 200067 200073 200070 200087 200064 200068 399886 200076 200062 399882 200056 200076 200074 399867 200073 200061 399882 200072 200076 200064 200055 200076 200076 200067 399866 200070 200068 399877 399875 200065 200072 200076 399871 200067 20005...
result:
ok 20337 lines
Test #10:
score: 10
Accepted
time: 580ms
memory: 53868kb
input:
200000 20334 4 4 3 1 3 4 3 3 2 1 2 4 1 3 4 4 2 4 3 4 2 2 2 3 4 2 1 4 1 1 4 3 4 3 1 1 1 2 3 4 1 4 3 3 4 1 3 1 2 4 3 4 1 2 4 2 1 2 3 4 4 1 1 4 1 1 3 2 3 4 4 1 4 1 2 1 2 1 1 3 4 1 1 3 4 2 1 1 4 4 4 3 4 4 4 2 3 3 4 2 3 1 3 4 4 3 3 2 2 3 4 2 4 2 4 3 3 3 4 1 4 4 1 1 4 4 3 1 1 1 2 4 3 4 2 3 3 3 2 4 4 3 4 2...
output:
4830334344 3994075737 200078 399875 599673 200058 200078 200088 200081 200071 200079 200073 200085 200074 200070 200084 200056 200059 200068 200068 200079 200082 200074 399875 200081 200069 200081 200072 200086 200086 200065 200064 399868 399862 200065 200072 399885 399875 399864 200078 200060 39988...
result:
ok 20334 lines
Extra Test:
score: 0
Extra Test Passed