Submission #971904

# Submission time Handle Problem Language Result Execution time Memory
971904 2024-04-29T13:05:11 Z Sunbae Vudu (COCI15_vudu) C++17
140 / 140
304 ms 32808 KB
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
const int N = 1e6 + 5;
vector<ll> cp;
ll bit[N], qs[N], P;
int m;
int pos(ll x){return upper_bound(cp.begin(), cp.end(), x) - cp.begin();}
void upd(int i){for(; i<=m; i+=i&-i) ++bit[i];}
ll qry(int i){ll res = 0; for(; i; i-=i&-i) res += bit[i]; return res;}
signed main(){
	int n; scanf("%d", &n);
	cp.clear(); fill(qs, qs+n+1, 0); fill(bit, bit+n+1, 0); 
	for(int i = 1; i<=n; ++i) scanf("%lld", qs+i);
	for(int i = 1; i<=n; ++i) qs[i] += qs[i-1];
	scanf("%lld", &P);
	for(ll i = 0; i<=n; ++i) cp.push_back(qs[i] - P*i);
	sort(cp.begin(), cp.end()); cp.resize(unique(cp.begin(), cp.end()) - cp.begin()); m = cp.size();
	upd(pos(0));
	ll Ans = 0;
	for(ll i = 1; i<=n; ++i){
		int x = pos(qs[i] - P*i);
		Ans += qry(x);
		upd(x);
	}
	printf("%lld", Ans);	
}

Compilation message

vudu.cpp: In function 'int main()':
vudu.cpp:12:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   12 |  int n; scanf("%d", &n);
      |         ~~~~~^~~~~~~~~~
vudu.cpp:14:33: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   14 |  for(int i = 1; i<=n; ++i) scanf("%lld", qs+i);
      |                            ~~~~~^~~~~~~~~~~~~~
vudu.cpp:16:7: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   16 |  scanf("%lld", &P);
      |  ~~~~~^~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 2 ms 2652 KB Output is correct
2 Correct 2 ms 2652 KB Output is correct
3 Correct 2 ms 2396 KB Output is correct
4 Correct 304 ms 32808 KB Output is correct
5 Correct 137 ms 24324 KB Output is correct
6 Correct 219 ms 30688 KB Output is correct
7 Correct 237 ms 30052 KB Output is correct
8 Correct 196 ms 28608 KB Output is correct
9 Correct 265 ms 32188 KB Output is correct
10 Correct 235 ms 29608 KB Output is correct