Submission #499018

# Submission time Handle Problem Language Result Execution time Memory
499018 2021-12-27T04:27:06 Z beksultan04 Money (IZhO17_money) C++14
0 / 100
1 ms 332 KB
#include <bits/stdc++.h>
using namespace std;
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
#define int long long
#define pii pair<int,int>
#define ret return
#define fr first
#define sc second
#define OK puts("OK");
#define NO puts("NO");
#define YES puts("YES");
#define all(s) s.begin(),s.end()
#define allr(s) s.rbegin(),s.rend()
#define nosol puts("-1");
#define pb push_back
#define endi puts("");
#define ordered_set tree <int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
const int N = 1e6+12,INF = 1e15+7;
int der[4*N];

void update(int v,int l,int r,int pos,int x){
	if (l == r){
		der[v] = x;
		ret;
	}
	int m = l+r>>1;
	if (m < pos)
		update((v<<1)+1,m+1,r,pos,x);
	else update(v<<1,l,m,pos,x);
	der[v] = der[v<<1]+der[(v<<1)+1];
}

int get_ans(int v,int l,int r,int ql,int qr){
	if (ql <= l && r <= qr)ret der[v];
	if (qr < l || r < ql)ret 0;
	int m = l+r>>1;
	ret get_ans(v<<1,l,m,ql,qr)+get_ans(v<<1|1,m+1,r,ql,qr);
}


main(){
	int n,i,x,y,ans=1;
	cin>>n;
	int p;
	cin>>p;
	for (i=2;i<=n;++i){
		cin>>x;
		if (x > p){
			int c = get_ans(1,1,1000000,p,x);
			if (c > 0)ans++;
		}
		else ans++;
		update(1,1,1000000,p,1);
		p = x;
	}
	cout <<ans;
	
}

Compilation message

money.cpp: In function 'void update(long long int, long long int, long long int, long long int, long long int)':
money.cpp:28:11: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   28 |  int m = l+r>>1;
      |          ~^~
money.cpp: In function 'long long int get_ans(long long int, long long int, long long int, long long int, long long int)':
money.cpp:38:11: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   38 |  int m = l+r>>1;
      |          ~^~
money.cpp: At global scope:
money.cpp:43:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   43 | main(){
      | ^~~~
money.cpp: In function 'int main()':
money.cpp:44:12: warning: unused variable 'y' [-Wunused-variable]
   44 |  int n,i,x,y,ans=1;
      |            ^
# Verdict Execution time Memory Grader output
1 Correct 0 ms 332 KB Output is correct
2 Correct 0 ms 332 KB Output is correct
3 Correct 0 ms 332 KB Output is correct
4 Incorrect 1 ms 332 KB Output isn't correct
5 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 332 KB Output is correct
2 Correct 0 ms 332 KB Output is correct
3 Correct 0 ms 332 KB Output is correct
4 Incorrect 1 ms 332 KB Output isn't correct
5 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 332 KB Output is correct
2 Correct 0 ms 332 KB Output is correct
3 Correct 0 ms 332 KB Output is correct
4 Incorrect 1 ms 332 KB Output isn't correct
5 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 332 KB Output is correct
2 Correct 0 ms 332 KB Output is correct
3 Correct 0 ms 332 KB Output is correct
4 Incorrect 1 ms 332 KB Output isn't correct
5 Halted 0 ms 0 KB -