QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#90551 | #5258. Mortgage | SolitaryDream# | WA | 1ms | 14548kb | C++20 | 2.3kb | 2023-03-23 16:23:09 | 2023-03-23 16:23:09 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
#define int long long
typedef pair<int, int> pii;
const int N = 2e5 + 10;
int n, m;
struct Point {
int x, y;
};
Point p[N];
Point operator+(Point u, Point v) { return {u.x + v.x, u.y + v.y}; }
Point operator-(Point u, Point v) { return {u.x - v.x, u.y - v.y}; }
int SDet(Point u, Point v) {
__int128 tmp = (__int128)u.x * v.y - (__int128)u.y * v.x;
return tmp < 0 ? -1 : tmp > 0;
}
namespace Seg {
vector<Point> g[N << 1];
inline void Build() {
for (int i = 1; i <= n; ++i)
for (int j = i + N; j; j >>= 1)
g[j].push_back(p[i]);
for (int t = N; t; --t) if (g[t].size() > 2) {
int tp = 2;
for (int i = 2; i < (int)g[t].size(); ++i) {
while (tp >= 2 && SDet(g[t][i] - g[t][tp - 2], g[t][tp - 1] - g[t][tp - 2]) >= 0) --tp;
g[t][tp++] = g[t][i];
}
g[t].resize(tp);
}
}
inline int Calc(Point b) {
// printf("* %lld %lld\n", b.x, b.y);
return b.y < 0 ? -1 : b.y / b.x;
}
inline int _Ask(Point b, int i) {
if (g[i].empty()) return 1e9;
int ans = Calc(g[i][0] - b);
for (auto l = g[i].begin() + 1, r = g[i].end(); l < r; ) {
auto mid = l + (r - l) / 2;
int p1 = Calc(*mid - b);
int p2 = Calc(*prev(mid) - b);
ans = min(ans, p1);
if (p2 < p1) l = mid + 1; else r = mid;
}
return ans;
}
inline int Ask(Point b, int x, int y) {
int ans = 1e9;
for (int l = N + x - 1, r = N + y + 1; l ^ r ^ 1; l >>= 1, r >>= 1) {
if (~l & 1) ans = min(ans, _Ask(b, l ^ 1));
if ( r & 1) ans = min(ans, _Ask(b, r ^ 1));
}
return ans;
}
}
signed main() {
scanf("%lld%lld", &n, &m);
for (int i = 1; i <= n; ++i) {
scanf("%lld", &p[i].y);
p[i].y += p[i - 1].y;
p[i].x = i;
}
Seg::Build();
for (int i = 1, x, y; i <= m; ++i) {
scanf("%lld%lld", &x, &y);
y = x + y - 1;
int ans = Seg::Ask(p[x - 1], x, y);
if (ans == -1) puts("stay with parents");
else printf("%lld\n", ans);
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 1ms
memory: 13244kb
input:
10 10 21 18 19 18 16 15 13 13 13 10 10 1 6 4 7 3 2 2 6 5 2 6 3 2 4 1 1 5 6 3
output:
10 13 13 18 12 16 18 18 18 13
result:
ok 10 lines
Test #2:
score: -100
Wrong Answer
time: 1ms
memory: 14548kb
input:
1000 1000 196 207 195 207 200 203 202 204 205 191 190 188 203 198 201 188 203 198 196 196 200 195 200 206 193 198 186 196 200 185 202 195 203 199 185 199 202 191 184 194 195 194 193 195 184 197 189 193 186 187 193 193 196 186 195 193 186 192 188 188 187 197 179 188 195 196 197 186 194 183 189 185 19...
output:
158 16 110 64 160 118 169 63 172 128 93 82 118 119 86 32 174 145 139 84 149 120 133 155 108 110 65 178 90 99 118 91 133 85 151 76 130 50 91 99 95 78 110 87 119 141 68 81 172 82 112 139 136 81 79 16 51 31 104 116 108 38 75 176 156 55 165 112 146 74 68 172 112 157 94 177 111 166 110 112 98 155 109 155...
result:
wrong answer 85th lines differ - expected: '105', found: '107'