# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
313804 |
2020-10-17T06:07:53 Z |
vivaan_gupta |
Vudu (COCI15_vudu) |
C++14 |
|
635 ms |
65540 KB |
#include <algorithm>
#include <bitset>
#include <cassert>
#include <chrono>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <limits>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <ratio>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
#include <climits>
#define ll long long
#define ld long double
#define mp make_pair
#define pb push_back
#define in insert
#define vll vector<ll>
#define endl "\n"
#define pll pair<ll,ll>
#define f first
#define s second
#define FOR(i,a,b) for(int i=(a),_b=(b); i<=_b; i++)
#define int ll
#define sz(x) (ll)x.size()
#define all(x) (x.begin(),x.end())
#define FOR(i,a,b) for (int i = (a); i < (b); ++i)
#define F0R(i,a) FOR(i,0,a)
#define ROF(i,a,b) for (int i = (b)-1; i >= (a); --i)
#define R0F(i,a) ROF(i,0,a)
#define trav(a,x) for (auto& a: x)
using namespace std;
const ll INF = 1e12;
const ll N =(2e6+5); // TODO : change value as per problem
const ll MOD = 1e9+7;
map<int, int> M;
ll cnt = 1;
ll bit[N];
void upd(int idx){
while(idx <= cnt){
bit[idx]++;
idx += (idx&(-idx));
}
}
ll query(int idx){
ll ans =0;
while(idx >= 1){
ans += bit[idx];
idx -= (idx&(-idx));
}
return ans;
}
void solve() {
// you should actually read the stuff at the bottom
int n;
cin >> n;
int a[n+1];
FOR(i,1,n+1) cin >> a[i];
int p;
cin >> p;
int pre[n+1];
pre[0] = 0;
FOR(i,1,n+1) pre[i] = pre[i-1] + a[i];
ll ans =0;
set<ll> gg;
FOR(i,1,n+1){
gg.in(pre[i] - p*i);
gg.in(pre[i-1] - p*i + p);
}
for(auto x:gg){
M[x] = cnt;
cnt++;
}
cnt--;
assert(cnt <= 2e6);
ROF(i,1,n+1){
upd(M[pre[i] - p*i]);
int tot = n-i+1;
tot -= query(M[pre[i-1] - p*i + p] - 1);
ans += tot;
}
cout << ans << endl;
}
signed main(){
ios_base::sync_with_stdio(0);
cin.tie(NULL);
// freopen(".in","r",stdin);freopen(".out","w",stdout);
ll tt=1;
// cin >> tt;
while(tt--){
solve();
}
}
Compilation message
vudu.cpp:45: warning: "FOR" redefined
45 | #define FOR(i,a,b) for (int i = (a); i < (b); ++i)
|
vudu.cpp:41: note: this is the location of the previous definition
41 | #define FOR(i,a,b) for(int i=(a),_b=(b); i<=_b; i++)
|
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
7 ms |
1280 KB |
Output is correct |
2 |
Correct |
5 ms |
1024 KB |
Output is correct |
3 |
Correct |
5 ms |
1024 KB |
Output is correct |
4 |
Runtime error |
635 ms |
65540 KB |
Execution killed with signal 9 (could be triggered by violating memory limits) |
5 |
Runtime error |
422 ms |
65540 KB |
Execution killed with signal 9 (could be triggered by violating memory limits) |
6 |
Runtime error |
507 ms |
65540 KB |
Execution killed with signal 9 (could be triggered by violating memory limits) |
7 |
Runtime error |
483 ms |
65540 KB |
Execution killed with signal 9 (could be triggered by violating memory limits) |
8 |
Runtime error |
479 ms |
65540 KB |
Execution killed with signal 9 (could be triggered by violating memory limits) |
9 |
Runtime error |
541 ms |
65536 KB |
Execution killed with signal 9 (could be triggered by violating memory limits) |
10 |
Runtime error |
492 ms |
65540 KB |
Execution killed with signal 9 (could be triggered by violating memory limits) |