QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#523933 | #2502. Fire | Dimash | 0 | 229ms | 51492kb | C++17 | 4.1kb | 2024-08-18 23:34:58 | 2024-08-18 23:34:59 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N = 4e5 + 12, MOD = (int)1e9 + 7;
int n,q,s[N];
struct fenw{
vector<ll> t;
void init(int n_) {
t.resize(n_+3);
}
void upd(int pos,ll val) {
while(pos <= n) {
t[pos] += val;
pos += (pos & -pos);
}
}
ll get(int i){
ll ret =0;
while(i) {
ret += t[i];
i -= i & -i;
}
return ret;
}
ll get(int l,int r) {
if(!l) return get(r);
return get(r) - get(l - 1);
}
};
fenw x,y;
ll t[N * 4], sum[N * 4], cmin[N * 4], cmax[N * 4], add[N * 4];
void assign(int v,ll val) {
add[v] += val;
cmin[v] += val;cmax[v] += val;
sum[v] += t[v] * val;
}
void push(int v) {
if(add[v]) {
assign(v + v,add[v]);
assign(v + v + 1,add[v]);
add[v] = 0;
}
}
void merge(int v) {
sum[v] = sum[v + v] + sum[v + v + 1];
cmin[v] = min(cmin[v + v],cmin[v + v + 1]);
cmax[v] = max(cmax[v + v],cmax[v + v + 1]);
t[v] = t[v + v] + t[v + v + 1];
}
void upd(int l,int r,int v = 1,int tl = 0,int tr = n ) {
if(l > r || tl > r || l > tr) return;
if(tl >= l && tr <= r) {
assign(v,1);
} else {
push(v);
int tm = (tl + tr) >> 1;
upd(l,r,v+v,tl,tm);
upd(l,r,v + v + 1,tm + 1,tr);
merge(v);
}
}
void upd1(int pos,ll val,int v = 1,int tl = 0,int tr = n) {
if(tl == tr) {
sum[v] = t[v] = val;
cmax[v] = cmin[v] = 1;
} else {
push(v);
int tm = (tl + tr) >> 1;
if(pos <= tm) upd1(pos,val,v+v,tl,tm);
else upd1(pos,val,v+v+1,tm+1,tr);
merge(v);
}
}
ll C[N];
ll get(int l,int r,int t_,int v = 1,int tl = 0,int tr = n) {
if(l > r || tl > r || l > tr) return 0;
if(tl >= l && tr <= r && tl == tr) {
ll cost = min((ll)t_,cmin[v]+C[tl]-1);
// cout << tl << ' ' << cost << '\n';
return cost * 1ll * t[v];
if(cmax[v] <= t_) {
return sum[v];
}
if(cmin[v] >= t_) {
// cout << tl << ' ' << tr << " " << cmin[v] << " " << t[v] << '\n';
return t[v] * 1ll * t_;
}
}
push(v);
int tm = (tl + tr) >> 1;
return get(l,r,t_,v+v,tl,tm) + get(l,r,t_,v+v+1,tm+1,tr);
}
ll find(int pos,int v = 1,int tl = 0,int tr = n) {
if(tl == tr) {
assert(cmax[v] == cmin[v]);
return cmax[v];
} else {
push(v);
int tm = (tl + tr) >> 1;
ll ret;
if(pos <= tm) ret = find(pos,v + v,tl,tm);
else ret = find(pos,v + v + 1,tm + 1,tr);
return ret;
}
}
ll ans[N],w[N],pref[N];
vector<array<int,2>> qr[N];
void test() {
cin >> n >> q;
for(int i = 1;i <= n;i++) {
cin >> s[i];
pref[i] = pref[i - 1] + s[i];
}
for(int i = 1;i <= q;i++) {
int l,r,t_;
cin >> t_ >> l >> r;
ans[i] += pref[r] - pref[l - 1];
qr[r].push_back({t_,i});
qr[l - 1].push_back({t_,i + q});
}
x.init(n);
y.init(n);
vector<int> st;
ll er = 0;
for(int i = 1;i <= n;i++) {
while(!st.empty() && s[st.back()] < s[i]) {
int j = st.back(),id = (int)st.size() - 1;
int c = find(id);
x.upd(c,w[j]);
y.upd(c,c*1ll*w[j]);
st.pop_back();
}
if((int)st.size()) {
w[i] = s[st.back()] - s[i];
C[(int)st.size()] = i - st.back();
er += (C[(int)st.size()]-1)* 1ll * w[i];
}
upd(0,(int)st.size() - 1);
upd1((int)st.size(),w[i]);
st.push_back(i);
for(auto [t_,id]:qr[i]) {
ans[id] += get(0,(int)st.size()-1,t_) + x.get(t_ + 1,n) * 1ll * t_ + y.get(0,t_) - er;
}
}
for(int i = 1;i <= q;i++) {
cout << ans[i] - ans[i + q] << '\n';
}
}
int main() {
ios_base::sync_with_stdio(false);cin.tie(0);
int t = 1;
// cin >> t;
while(t--) {
test();
}
}
詳細信息
Subtask #1:
score: 0
Wrong Answer
Test #1:
score: 1
Accepted
time: 0ms
memory: 25436kb
input:
1 1 551303100 1 1 1
output:
551303100
result:
ok single line: '551303100'
Test #2:
score: 0
Wrong Answer
time: 0ms
memory: 28844kb
input:
195 190 882633810 151128639 704686762 226822928 265484923 605396999 600317503 147035574 899924275 685957574 40322376 957940188 365896511 568700043 384793703 949202250 887417738 844311315 972780491 145788153 546225097 535298105 465373805 130957600 219578976 122448549 433761633 281023080 118205349 658...
output:
26211256194 8534564450 9346362015 9907599378 9283245000 21189963564 68326502979 11911775203 52697688975 87878822207 21814886179 11780624791 9283245000 989029061 31391774946 58988596513 8285017238 10281472762 98258448875 31915633453 9227021755 1945560982 46028399285 55155121847 54401576241 3240824062...
result:
wrong answer 1st lines differ - expected: '30943577373', found: '26211256194'
Subtask #2:
score: 0
Wrong Answer
Test #33:
score: 0
Wrong Answer
time: 224ms
memory: 48752kb
input:
193587 195267 240887478 241952733 735641315 241225435 601212681 739513769 299705266 744678976 209860766 472944474 72780744 767142988 11106288 337834413 996287812 292438064 381597678 596795763 871700460 160422576 715150339 172971733 887180291 543480710 679621383 193121808 831187946 472128389 95554440...
output:
72593768728118 67738320827125 51837565939826 15852131482364 1381171912999 57399852685342 32987753805450 28422194017773 65297583812990 64271198661105 118486826154486 96159298886206 4338755636272 52030600371344 129022747990569 6413830097125 36699835712185 41542452135899 17327958843934 20225492277008 4...
result:
wrong answer 1st lines differ - expected: '96732267183549', found: '72593768728118'
Subtask #3:
score: 0
Wrong Answer
Test #59:
score: 0
Wrong Answer
time: 204ms
memory: 50700kb
input:
195126 192880 610630859 940495514 143112709 651093025 196907895 712808532 243882601 357737320 195770873 652324164 983838341 877082163 556111136 477845990 794892854 282153340 15033444 676107981 701186972 679723027 249521100 808983410 566115583 758465392 114336563 811876489 50897056 44462271 104396801...
output:
22648215602021 50766414757441 65450249557602 41630494925235 55854903899120 3424138038696 568681035952 25285634157270 83986656891899 39380322875140 1491169943537 34795239040211 14213008599405 28566416328794 40205768393700 28110644343819 4261195915894 15032592643872 960901246522 3250997189991 62187094...
result:
wrong answer 1st lines differ - expected: '30350964336661', found: '22648215602021'
Subtask #4:
score: 0
Wrong Answer
Test #74:
score: 0
Wrong Answer
time: 229ms
memory: 51492kb
input:
193950 199534 130102065 353778382 626811172 289831276 591286736 485830103 540993883 410675214 327559603 95586376 670972593 144909727 131704463 149806058 108266251 237481299 772380159 821295997 597620088 302173842 551746997 416493887 721330731 97699904 737743769 834745312 791384607 825151897 41002378...
output:
999946039 826683848 999976490 999657580 999949780 999989395 999817666 999989395 -173742869 999989395 134958785 965117697 999976490 999989395 996090320 999989395 516249817 678684795 326673107 827251634 999990751 999989395 999989395 381867673 999976490 999989395 999990751 999949780 999898847 411149855...
result:
wrong answer 2nd lines differ - expected: '999971198', found: '826683848'
Subtask #5:
score: 0
Skipped
Dependency #1:
0%