QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#65531 | #3850. DJ Darko | UBB_Zalau00# | WA | 655ms | 51032kb | C++14 | 4.6kb | 2022-12-01 16:52:27 | 2022-12-01 16:52:29 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
const long long inf = 1e18;
struct node_t{
long long __min;
long long __max;
long long __sum;
int count = 0;
pair<long long, long long> lazy;
node_t(){
this->__min = inf;
this->__max = -inf;
this->__sum = 0;
this->count = 0;
this->lazy = {1, 0};
}
node_t(const pair<int, int> &value) {
this->__min = value.first;
this->__max = value.first;
this->__sum = value.second;
this->count = 1;
this->lazy = {1, 0};
}
node_t operator + (const node_t& other)const{
node_t answer;
answer.__min = min(this->__min, other.__min);
answer.__max = max(this->__max, other.__max);
answer.__sum = this->__sum + other.__sum;
answer.lazy = {1, 0};
answer.count = this->count + other.count;
return answer;
}
void propagate(const pair<long long, long long> &lazy) {
this->__min = lazy.first * __min + lazy.second;
this->__max = lazy.first * __max + lazy.second;
if(this->__min > this->__max){
swap(this->__min, this->__max);
}
this->lazy = {lazy.first * this->lazy.first, lazy.first * this->lazy.second + lazy.second};
}
};
class SegmentTree{
int n;
vector<node_t> aint;
void build(int nod, int st, int dr, const vector<pair<int, int> > &values) {
if(st == dr){
aint[nod] = node_t(values[st]);
return ;
}
int mid = (st + dr) / 2;
build(nod * 2, st, mid, values);
build(nod * 2 + 1, mid + 1, dr, values);
aint[nod] = aint[nod * 2] + aint[nod * 2 + 1];
}
void propagate(int nod, int st, int dr){
if(st == dr){
return ;
}
aint[nod * 2].propagate(aint[nod].lazy);
aint[nod * 2 + 1].propagate(aint[nod].lazy);
aint[nod].lazy = {1, 0};
}
void update(int nod, int st, int dr, int l, int r, const pair<int, int> &lazy) {
propagate(nod, st , dr);
if(r < st || l > dr){
return ;
}
if(l <= st && dr <= r){
aint[nod].propagate(lazy);
return ;
}
int mid = (st + dr) / 2;
update(nod * 2, st, mid, l, r, lazy);
update(nod * 2 + 1, mid + 1, dr, l, r, lazy);
aint[nod] = aint[nod * 2] + aint[nod * 2 + 1];
}
void getBuckets(int nod, int st, int dr, int l, int r, vector<node_t> &answer) {
propagate(nod, st, dr);
if(dr < l || st > r){
return ;
}
if(l <= st && dr <= r && aint[nod].__min == aint[nod].__max){
answer.push_back(aint[nod]);
return ;
}
int mid = (st + dr) / 2;
getBuckets(nod * 2, st, mid, l, r, answer);
getBuckets(nod * 2 + 1, mid + 1, dr, l, r, answer);
}
public:
SegmentTree(const vector<pair<int, int> > &v){
this->n = v.size();
this->aint = vector<node_t>(4 * n + 5);
this->build(1, 1, n, v);
}
void updateSet(int st, int dr, int value){
this->update(1, 1, n, st, dr, make_pair(0, value));
}
void updateAdd(int st, int dr, int value){
this->update(1, 1, n, st, dr, make_pair(1, value));
}
vector<pair<long long, long long> > getBuckets(int l, int r){
vector<node_t> node_answer;
this->getBuckets(1, 1, n, l, r, node_answer);
sort(node_answer.begin(), node_answer.end(), [](const node_t &a, const node_t &b){
return a.__min < b.__min;
});
vector<pair<long long, long long > > answer;
for(auto it:node_answer){
if(answer.empty() || answer.back().first != it.__min){
answer.push_back({it.__min, 0});
}
answer.back().second += it.__sum;
}
return answer;
}
};
int main(){
int n, q;
scanf("%d %d", &n, &q);
vector<pair<int, int> > values(n + 1);
for(int i = 1;i <= n;i++){
scanf("%d", &values[i].first);
}
for(int i = 1;i <= n;i++){
scanf("%d", &values[i].second);
}
SegmentTree aint(values);
while(q--){
int t;
scanf("%d", &t);
if(t == 1){
int l, r, x;
scanf("%d %d %d", &l, &r, &x);
aint.updateAdd(l, r, x);
} else {
int l, r;
scanf("%d %d", &l, &r);
vector<pair<long long, long long> > buckets = aint.getBuckets(l, r);
long long total_sum = 0;
for(auto it:buckets){
// printf("debug bucket %lld %lld\n", it.first, it.second);
total_sum += it.second;
}
long long prefix_sum = 0;
long long level = 0;
for(auto it:buckets){
if(prefix_sum - (total_sum - prefix_sum) >= 0){
break;
}
prefix_sum += it.second;
level = it.first;
}
aint.updateSet(l, r, level);
printf("%lld\n", level);
}
}
return 0;
}
详细
Test #1:
score: 0
Wrong Answer
time: 655ms
memory: 51032kb
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...
result:
wrong answer 45th lines differ - expected: '-3237387922', found: '1057579374'