#include<bits/stdc++.h>
#include<fstream>
using namespace std;
//#pragma GCC optimize("O3")
#define sz(a) (int)a.size()
#define ALL(v) v.begin(), v.end()
#define ALLR(v) v.rbegin(), v.rend()
#define ll long long
#define pb push_back
#define forr(i, a, b) for(int i = a; i < b; i++)
#define dorr(i, a, b) for(int i = a; i >= b; i--)
#define ld long double
#define vt vector
#include<fstream>
#define fi first
#define se second
#define pll pair<ll, ll>
#define pii pair<int, int>
#define mpp make_pair
const ld PI = 3.14159265359, prec = 1e-9;;
//using u128 = __uint128_t;
//const int x[4] = {1, 0, -1, 0};
//const int y[4] = {0, -1, 0, 1};
ll mod = 998244353, pr = 69;
const int mxn = 3e5 + 5, mxq = 1e5 + 5, sq = 1005, mxv = 5e4 + 1, lg = 60;
//const int base = (1 <<18);
const ll inf = 2e9 + 5, neg = -69420, inf2 = 1e14;
mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
int n, q;
int dp[mxn + 1][2], a[mxn + 1], d[mxn + 1];
int sign(ll x){
if(x < 0)return(0);
if(x > 0)return(1);
return(2);
}
int rev(int x){
if(x == 0)return(1);
if(x == 1)return(0);
return(-1);
}
void solve(){
cin >> n >> q;
for(int i = 1; i <= n; i++)cin >> a[i];
for(int i = 1; i < n; i++){
d[i] = a[i + 1] - a[i];
}
while(q--){
char idq; cin >> idq;
if(idq == '*'){
int l, r; cin >> l >> r;
for(int i = l; i <= r; i++)a[i] *= -1;
}else if(idq == '+'){
int l, r; ll v; cin >> l >> r >> v;
for(int i = l; i <= r; i++)a[i] += v;
}else{
int l, r; cin >> l >> r;
ll ans = 0;
for(int i = l; i < r;){
if(sign(d[i]) == 2){
i++; continue;
}
int rp = i + 1;
while(rp < r && sign(d[rp - 1]) == rev(sign(d[rp]))){
rp++;
}
ans += 1LL * (rp - i) * (rp - i + 1) / 2;
i = rp;
}
cout << ans + r - l + 1 << "\n";
}
for(int i = 1; i < n; i++){
d[i] = a[i + 1] - a[i];
}
}
}
signed main(){
ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
//freopen("TESTROOMS.inp", "r", stdin);
//freopen("TESTROOMS.out", "w", stdout);
int tt; tt = 1;
while(tt--){
solve();
}
return(0);
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
20 ms |
2392 KB |
Output is correct |
2 |
Incorrect |
19 ms |
2648 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
2041 ms |
5712 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
20 ms |
2392 KB |
Output is correct |
2 |
Incorrect |
19 ms |
2648 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
20 ms |
2392 KB |
Output is correct |
2 |
Incorrect |
19 ms |
2648 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |