답안 #313844

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
313844 2020-10-17T07:12:14 Z vivaan_gupta Vudu (COCI15_vudu) C++14
0 / 140
413 ms 65540 KB
		#include <algorithm>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#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;
using namespace __gnu_pbds;
typedef cc_hash_table<ll, ll, hash<ll>> ht; 

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


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

	sort(gg.begin(),gg.end());
	// assert(gg.size() == 2*n);
	for(int i =0;i<gg.size();){
		int j =i;
		while(j < gg.size() && gg[j].f == gg[i].f){
			if(gg[j].s.f == 0){
				lol[gg[j].s.s] = cnt;
			}
			else{
				lol2[gg[j].s.s] = cnt;
			}
			j++;
		}
		cnt++;
		i = j;
	}
	cnt--;
	// for(int i =1;i<=n;i++){
	// 	cout << lol[i] << " ";
	// 	cout << endl;
	// }
	// // assert(cnt <= 2e6);
	// FOR(i,1,n+1) {
	// 	lol[i] = M[pre[i] - p*i];
	// 	lol2[i] = M[pre[i-1] - p*i + p];	
	// }
	
	// ROF(i,1,n+1){
	// 	upd(lol[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:99:16: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<std::pair<long long int, std::pair<long long int, long long int> > >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   99 |  for(int i =0;i<gg.size();){
      |               ~^~~~~~~~~~
vudu.cpp:101:11: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<std::pair<long long int, std::pair<long long int, long long int> > >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  101 |   while(j < gg.size() && gg[j].f == gg[i].f){
      |         ~~^~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Incorrect 3 ms 1148 KB Output isn't correct
2 Incorrect 2 ms 1020 KB Output isn't correct
3 Incorrect 3 ms 960 KB Output isn't correct
4 Runtime error 397 ms 65540 KB Execution killed with signal 9 (could be triggered by violating memory limits)
5 Incorrect 230 ms 58412 KB Output isn't correct
6 Runtime error 373 ms 65540 KB Execution killed with signal 9 (could be triggered by violating memory limits)
7 Runtime error 374 ms 65540 KB Execution killed with signal 9 (could be triggered by violating memory limits)
8 Incorrect 321 ms 62032 KB Output isn't correct
9 Runtime error 413 ms 65540 KB Execution killed with signal 9 (could be triggered by violating memory limits)
10 Runtime error 357 ms 65540 KB Execution killed with signal 9 (could be triggered by violating memory limits)