답안 #313864

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
313864 2020-10-17T07:36:51 Z vivaan_gupta Vudu (COCI15_vudu) C++14
140 / 140
419 ms 56328 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 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 ROF(i,a,b) for (int i = (b)-1; i >= (a); --i)

using namespace std;

 
const ll N =(1e6+5); // TODO : change value as per problem
const ll MOD = 1e9+7;


ll cnt = 1;
ll bit[N];
int lol2[N];
int pre[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;
	pre[0] = 0;
	FOR(i,1,n+1) {
		int a;
		cin >> a;
		pre[i] = pre[i-1] + a;
	}
	int p;
	cin >> p;
	ll ans =0;
	vector <pair<ll,ll>> gg;
	FOR(i,1,n+1){
		gg.pb(mp(pre[i] - p*i,i));
		gg.pb(mp(pre[i-1] - p*i + p,i+n));
	}

	sort(gg.begin(),gg.end());
	for(int i =0;i<gg.size();){
		int j =i;
		while(j < gg.size() && gg[j].f == gg[i].f){
			if(gg[j].s <= n){
				pre[gg[j].s] = cnt;
			}
			else{
				lol2[gg[j].s-n] = cnt;
			}
			j++;
		}
		cnt++;
		i = j;
	}
	cnt--;	
	ROF(i,1,n+1){
		upd(pre[i]);
		int tot = n-i+1;
		tot -=  query(lol2[i] - 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: In function 'void solve()':
vudu.cpp:92:16: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<std::pair<long long int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   92 |  for(int i =0;i<gg.size();){
      |               ~^~~~~~~~~~
vudu.cpp:94:11: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<std::pair<long long int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   94 |   while(j < gg.size() && gg[j].f == gg[i].f){
      |         ~~^~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 1024 KB Output is correct
2 Correct 3 ms 896 KB Output is correct
3 Correct 2 ms 768 KB Output is correct
4 Correct 415 ms 54560 KB Output is correct
5 Correct 241 ms 38740 KB Output is correct
6 Correct 348 ms 48456 KB Output is correct
7 Correct 375 ms 50372 KB Output is correct
8 Correct 323 ms 43932 KB Output is correct
9 Correct 419 ms 56328 KB Output is correct
10 Correct 353 ms 49180 KB Output is correct