Submission #1083927

# Submission time Handle Problem Language Result Execution time Memory
1083927 2024-09-04T14:18:58 Z hungeazy Vudu (COCI15_vudu) C++17
140 / 140
240 ms 33568 KB
/*
* @Author: hungeazy
* @Date:   2024-09-04 21:08:59
* @Last Modified by:   hungeazy
* @Last Modified time: 2024-09-04 21:18:30
*/
#include <bits/stdc++.h>
// #pragma GCC optimize("O3")  
// #pragma GCC optimize("unroll-loops")  
// #pragma GCC target("avx2,bmi,bmi2,popcnt,lzcnt")  
using namespace std;
#define fast ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define int long long
#define ull unsigned long long
#define sz(x) x.size()
#define sqr(x) (1LL * (x) * (x))
#define all(x) x.begin(), x.end()
#define fill(f,x) memset(f,x,sizeof(f))
#define FOR(i,l,r) for(int i=l;i<=r;i++)
#define FOD(i,r,l) for(int i=r;i>=l;i--)
#define ii pair<int,int>
#define iii pair<int,ii>
#define di pair<ii,ii>
#define vi vector<int>
#define vii vector<ii>
#define mii map<int,int>
#define fi first
#define se second
#define pb push_back
#define MOD 1000000007
#define __lcm(a,b) (1ll * ((a) / __gcd((a), (b))) * (b))
#define YES cout << "YES\n"
#define NO cout << "NO\n"
#define MASK(i) (1LL << (i))
#define c_bit(i) __builtin_popcountll(i)
#define BIT(x,i) ((x) & MASK(i))
#define SET_ON(x,i) ((x) | MASK(i))
#define SET_OFF(x,i) ((x) & ~MASK(i))
#define oo 1e18
#define name "AVERAGE"
#define endl '\n'
#define time() cerr << endl << "-------------Time:" << 1000.0 * clock() / CLOCKS_PER_SEC << "ms.";
template<typename T> bool maximize(T &res, const T &val) { if (res < val){ res = val; return true; }; return false; }
template<typename T> bool minimize(T &res, const T &val) { if (res > val){ res = val; return true; }; return false; }
const int N = (int)1e6+10;
int a[N],n,p;

namespace hungeazy {

	int bit[N];

	void update(int pos)
	{
		int id = pos;
		while (id < N)
		{
			bit[id]++;
			id += (id&(-id));
		}
	}

	int get(int pos)
	{
		int id = pos, ans = 0;
		while (id)
		{
			ans += bit[id];
			id -= (id&(-id));
		}
		return ans;
	}

	void solve(void)
	{
		vi v;
		int s = 0;
		FOR(i,1,n) s += a[i], s -= p, v.pb(s);
		sort(all(v));
		v.erase(unique(all(v)),v.end());
		int ans = 0; s = 0;
		FOR(i,0,n)
		{
			s += a[i];
			if (i) s -= p;
			int val = lower_bound(all(v),s)-v.begin()+1;
			ans += get(val);
			update(val);
		}
		cout << ans;
	}
	
}

signed main()
{
    fast;
    if (fopen(name".inp","r"))
    {
    	freopen(name".inp","r",stdin);
    	freopen(name".out","w",stdout);
    }
    cin >> n;
    FOR(i,1,n) cin >> a[i];
    cin >> p;
    hungeazy::solve();
    time();
    return 0;
}
// ██░ ██  █    ██  ███▄    █   ▄████
//▓██░ ██▒ ██  ▓██▒ ██ ▀█   █  ██▒ ▀█▒
//▒██▀▀██░▓██  ▒██░▓██  ▀█ ██▒▒██░▄▄▄░
//░▓█ ░██ ▓▓█  ░██░▓██▒  ▐▌██▒░▓█  ██▓
//░▓█▒░██▓▒▒█████▓ ▒██░   ▓██░░▒▓███▀▒
// ▒ ░░▒░▒░▒▓▒ ▒ ▒ ░ ▒░   ▒ ▒  ░▒   ▒
// ▒ ░▒░ ░░░▒░ ░ ░ ░ ░░   ░ ▒░  ░   ░
// ░  ░░ ░ ░░░ ░ ░    ░   ░ ░ ░ ░   ░
// ░  ░  ░   ░              ░       ░

Compilation message

vudu.cpp: In function 'int main()':
vudu.cpp:99:13: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   99 |      freopen(name".inp","r",stdin);
      |      ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~
vudu.cpp:100:13: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
  100 |      freopen(name".out","w",stdout);
      |      ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 2 ms 6744 KB Output is correct
2 Correct 2 ms 6744 KB Output is correct
3 Correct 2 ms 6748 KB Output is correct
4 Correct 240 ms 32808 KB Output is correct
5 Correct 134 ms 22956 KB Output is correct
6 Correct 196 ms 29924 KB Output is correct
7 Correct 203 ms 31928 KB Output is correct
8 Correct 187 ms 29476 KB Output is correct
9 Correct 232 ms 33568 KB Output is correct
10 Correct 207 ms 30368 KB Output is correct