QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#187513 | #3850. DJ Darko | ballance# | TL | 0ms | 0kb | C++23 | 1.7kb | 2023-09-24 17:54:15 | 2023-09-24 17:54:15 |
answer
#include <cstdio>
#include <algorithm>
#include <queue>
using namespace std;
#define MAX 200000
long long A[MAX + 1];
long long B[MAX + 1];
long long sum_B[MAX + 1] = {};
class Node{
public:
long long numA;
long long numB;
Node(long long a, long long b): numA(a), numB(b) {}
Node() {}
bool operator< (const Node b) const{
return this->numA < b.numA;
}
bool operator> (const Node b) const{
return this->numA > b.numA;
}
}Nodes[MAX + 1];
int main(){
int N, Q;
scanf("%d %d", &N, &Q);
for (int i = 1; i <= N; i++)
scanf("%lld", &A[i]);
sum_B[0] = 0;
for (int j = 1; j <= N; j++){
scanf("%lld", &B[j]);
Nodes[j] = Node(A[j], B[j]);
sum_B[j] = sum_B[j - 1] + B[j];
}
while (Q--){
int ord, l, r;
scanf("%d %d %d", &ord, &l, &r);
if (ord == 1){
int x;
scanf("%d", &x);
for (int i = l; i <= r; i++)
Nodes[i].numA += x;
continue;
}
if (l == r){
printf("%lld\n", Nodes[l].numA);
continue;
}
long long totalB = - (sum_B[r] - sum_B[l - 1]);
sort(Nodes + l, Nodes + r + 1, less<Node>());
int i = l;
for (; i <= r; i++)
{
totalB += 2 * Nodes[i].numB;
if (totalB >= 0)
break;
}
long long adj = Nodes[i].numA;
printf("%lld\n", adj);
for (i = l; i <= r; i++){
Nodes[i].numA = adj;
Nodes[i].numB = B[i];
}
}
return 0;
}
詳細信息
Test #1:
score: 0
Time Limit Exceeded
input:
200000 200000 185413631 745038744 881479208 394948467 101727403 796960399 284541402 80768155 286582974 546327406 197495962 552359542 727479505 437895671 143092948 7626834 741609268 540494577 298656274 548860413 41137417 210529949 658779847 161355446 486548926 602900245 119414972 310187428 238177860 ...
output:
462406736 1749348519 1749348519 467651597 874061694 874061694 874061694 874061694 -1521749 874061694 -893932302 -425504259 -425504259 332034115 332034115 86195778 86195778 86195778 86195778 86195778 -425504259 -165776398 -165776398 -165776398 -916781043 -254293799 -254293799 -254293799 -254293799 -8...