QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#537689 | #5258. Mortgage | UESTC_DECAYALI | WA | 2ms | 7656kb | C++20 | 2.0kb | 2024-08-30 17:27:45 | 2024-08-30 17:27:45 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
const int N = 2e5+5;
int n, m, A[N], sum[N];
struct Node{
int R, id;
bool operator<(const Node &b)const{return R!=b.R ? R>b.R : id<b.id;}
};
vector<Node> qry[N];
int ans[N];
struct Convh{
vector<int> stk; int sz=0;
void add(int id){
while (sz>1 &&
(sum[stk[sz-1]]-sum[id])*(stk[sz-2]-stk[sz-1]) >
(sum[stk[sz-2]]-sum[stk[sz-1]])*(stk[sz-1]-id))
stk.pop_back(), --sz;
stk.push_back(id); ++sz;
}
int find(int id){
int L=0, R=sz-1;
while (R - L > 3){
int M1 = L+(R-L)/2, M2 = M1+1;
int res1 = (sum[stk[M1]]-sum[id])*(stk[M2]-id);
int res2 = (sum[stk[M2]]-sum[id])*(stk[M1]-id);
if (res1 == res2) L=R;
else if (res1 < res2) L=M1;
else R = M2;
std::cerr << "FUCK\n";
}
int ans = 0x3f3f3f3f;
while(L <= R) ans = min(ans, (sum[stk[L]]-sum[id])/(stk[L]-id)), L++;
if (ans>=0) return ans;
else return -1;
}
};
Convh c[N];
signed main(){
ios::sync_with_stdio(0); cin.tie(0);
cin >> n >> m;
for (int i=1; i<=n; ++i) cin >> A[i], sum[i] = sum[i-1]+A[i];
for (int i=1; i<=m; ++i){
int s, k; cin >> s >> k;
qry[s-1].push_back(Node{s+k-1, i});
}
for (int i=0; i<n; ++i) sort(qry[i].begin(), qry[i].end());
for (int i=n; i>=0; --i){
for(auto [q, id]: qry[i]) {
int l = i + 1, r = q + 1, a = 0x7f7f7f7f;
for(int j = r; j > l; j -= j&-j) if(c[j].sz) a = std::min(a, c[j].find(l - 1));// std::cerr << "FUCK\n";
ans[id] = a;
}
for(int j = i + 1; j <= n + 1; j += j&-j) c[j].add(i);// std::cerr << "Blyat\n";
}
for(int i = 1; i <= m; ++i) {
if(ans[i] < 0) std::cout << "stay with parents\n";
else std::cout << ans[i] << char(10);
}
return 0;
}
详细
Test #1:
score: 100
Accepted
time: 2ms
memory: 7656kb
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: 2ms
memory: 3720kb
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 186th lines differ - expected: '108', found: '111'