Submission #736835

# Submission time Handle Problem Language Result Execution time Memory
736835 2023-05-06T09:29:40 Z MODDI Happiness (Balkan15_HAPPINESS) C++14
Compilation error
0 ms 0 KB
#include "happiness.h"
//#include "grader.cpp"
#include <bits/stdc++.h>
using namespace std;
ll mx;
struct Node{
	ll sum, tl, tr;
	int l, r;
	Node() : sum(0), l(-1), r(-1){}
};
Node tree[40 * 200010];
int cnt = 2;
void update(int node, ll pos, ll add){
	if(tree[node].tl == tree[node].tr && tree[node].tl == pos){
		tree[node].sum += add;
		return;
	}
	else{
		ll mid = (tree[node].tl + tree[node].tr) / 2;
		if(tree[node].l == -1){
			tree[node].l = cnt++;
			tree[tree[node].l].tl = tree[node].tl;
			tree[tree[node].l].tr = mid;
		}
		if(tree[node].r == -1){
			tree[node].r = cnt++;
			tree[tree[node].r].tl = mid+1;
			tree[tree[node].r].tr = tree[node].tr;
		}
		if(pos <= mid){
			update(tree[node].l, pos, add);
		}
		else
			update(tree[node].r, pos, add);
			
		tree[node].sum = tree[tree[node].l].sum + tree[tree[node].r].sum;
	}
}
ll query(int node, ll l, ll r){
	if(tree[node].tl > r || tree[node].tr < l)	return 0;
	if(l == tree[node].tl && tree[node].tr == r) return tree[node].sum;
	else{
		ll mid=(tree[node].tl + tree[node].tr) /2;
		if(tree[node].l == -1){
			tree[node].l = cnt++;
			tree[tree[node].l].tl = tree[node].tl;
			tree[tree[node].l].tr = mid;
		}
		if(tree[node].r == -1){
			tree[node].r = cnt++;
			tree[tree[node].r].tl = mid+1;
			tree[tree[node].r].tr = tree[node].tr;
		}
		if(l > mid)	return query(tree[node].r, l, r);
		else if(r <= mid)	return query(tree[node].l, l, r);
		else{
			return query(tree[node].l, l, mid) + query(tree[node].r, mid+1, r);
		}
	}
	
}
bool check(){
	ll coin = 1, tot = query(1, 1, mx);
	while(coin <= mx){
		ll sum = query(1, 1, coin);
		if(sum + 1 > mx)	return true;
		if(tot == sum)	return true;
		if(query(1, coin+1, sum+1) == 0)	return false;
		coin = sum + 1;
	}
	return true;
}
bool init(int n, ll M, ll a[]){
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	mx = M;
	tree[1].sum = 0;
	tree[1].tl = 1;
	tree[1].tr = 1e12;
	for(int i = 0; i < n; i++)
		update(1, a[i], a[i]);
		
	return check();
}
bool is_happy(int e, int n, ll a[]){
	for(int i = 0; i < n; i++)
		update(1, a[i], a[i]*e);
		
	return check();
}

Compilation message

happiness.cpp:5:1: error: 'll' does not name a type
    5 | ll mx;
      | ^~
happiness.cpp:7:2: error: 'll' does not name a type
    7 |  ll sum, tl, tr;
      |  ^~
happiness.cpp: In constructor 'Node::Node()':
happiness.cpp:9:11: error: class 'Node' does not have any field named 'sum'
    9 |  Node() : sum(0), l(-1), r(-1){}
      |           ^~~
happiness.cpp: At global scope:
happiness.cpp:13:23: error: 'll' has not been declared
   13 | void update(int node, ll pos, ll add){
      |                       ^~
happiness.cpp:13:31: error: 'll' has not been declared
   13 | void update(int node, ll pos, ll add){
      |                               ^~
happiness.cpp: In function 'void update(int, int, int)':
happiness.cpp:14:16: error: 'struct Node' has no member named 'tl'; did you mean 'l'?
   14 |  if(tree[node].tl == tree[node].tr && tree[node].tl == pos){
      |                ^~
      |                l
happiness.cpp:14:33: error: 'struct Node' has no member named 'tr'; did you mean 'r'?
   14 |  if(tree[node].tl == tree[node].tr && tree[node].tl == pos){
      |                                 ^~
      |                                 r
happiness.cpp:14:50: error: 'struct Node' has no member named 'tl'; did you mean 'l'?
   14 |  if(tree[node].tl == tree[node].tr && tree[node].tl == pos){
      |                                                  ^~
      |                                                  l
happiness.cpp:15:14: error: 'struct Node' has no member named 'sum'
   15 |   tree[node].sum += add;
      |              ^~~
happiness.cpp:19:3: error: 'll' was not declared in this scope
   19 |   ll mid = (tree[node].tl + tree[node].tr) / 2;
      |   ^~
happiness.cpp:22:23: error: 'struct Node' has no member named 'tl'; did you mean 'l'?
   22 |    tree[tree[node].l].tl = tree[node].tl;
      |                       ^~
      |                       l
happiness.cpp:22:39: error: 'struct Node' has no member named 'tl'; did you mean 'l'?
   22 |    tree[tree[node].l].tl = tree[node].tl;
      |                                       ^~
      |                                       l
happiness.cpp:23:23: error: 'struct Node' has no member named 'tr'; did you mean 'r'?
   23 |    tree[tree[node].l].tr = mid;
      |                       ^~
      |                       r
happiness.cpp:23:28: error: 'mid' was not declared in this scope
   23 |    tree[tree[node].l].tr = mid;
      |                            ^~~
happiness.cpp:27:23: error: 'struct Node' has no member named 'tl'; did you mean 'l'?
   27 |    tree[tree[node].r].tl = mid+1;
      |                       ^~
      |                       l
happiness.cpp:27:28: error: 'mid' was not declared in this scope
   27 |    tree[tree[node].r].tl = mid+1;
      |                            ^~~
happiness.cpp:28:23: error: 'struct Node' has no member named 'tr'; did you mean 'r'?
   28 |    tree[tree[node].r].tr = tree[node].tr;
      |                       ^~
      |                       r
happiness.cpp:28:39: error: 'struct Node' has no member named 'tr'; did you mean 'r'?
   28 |    tree[tree[node].r].tr = tree[node].tr;
      |                                       ^~
      |                                       r
happiness.cpp:30:13: error: 'mid' was not declared in this scope
   30 |   if(pos <= mid){
      |             ^~~
happiness.cpp:36:14: error: 'struct Node' has no member named 'sum'
   36 |   tree[node].sum = tree[tree[node].l].sum + tree[tree[node].r].sum;
      |              ^~~
happiness.cpp:36:39: error: 'struct Node' has no member named 'sum'
   36 |   tree[node].sum = tree[tree[node].l].sum + tree[tree[node].r].sum;
      |                                       ^~~
happiness.cpp:36:64: error: 'struct Node' has no member named 'sum'
   36 |   tree[node].sum = tree[tree[node].l].sum + tree[tree[node].r].sum;
      |                                                                ^~~
happiness.cpp: At global scope:
happiness.cpp:39:1: error: 'll' does not name a type
   39 | ll query(int node, ll l, ll r){
      | ^~
happiness.cpp: In function 'bool check()':
happiness.cpp:63:2: error: 'll' was not declared in this scope
   63 |  ll coin = 1, tot = query(1, 1, mx);
      |  ^~
happiness.cpp:64:8: error: 'coin' was not declared in this scope
   64 |  while(coin <= mx){
      |        ^~~~
happiness.cpp:64:16: error: 'mx' was not declared in this scope
   64 |  while(coin <= mx){
      |                ^~
happiness.cpp:65:5: error: expected ';' before 'sum'
   65 |   ll sum = query(1, 1, coin);
      |     ^~~~
      |     ;
happiness.cpp:66:6: error: 'sum' was not declared in this scope
   66 |   if(sum + 1 > mx) return true;
      |      ^~~
happiness.cpp:67:6: error: 'tot' was not declared in this scope
   67 |   if(tot == sum) return true;
      |      ^~~
happiness.cpp:67:13: error: 'sum' was not declared in this scope
   67 |   if(tot == sum) return true;
      |             ^~~
happiness.cpp:68:23: error: 'sum' was not declared in this scope
   68 |   if(query(1, coin+1, sum+1) == 0) return false;
      |                       ^~~
happiness.cpp:68:6: error: 'query' was not declared in this scope
   68 |   if(query(1, coin+1, sum+1) == 0) return false;
      |      ^~~~~
happiness.cpp:69:10: error: 'sum' was not declared in this scope
   69 |   coin = sum + 1;
      |          ^~~
happiness.cpp: At global scope:
happiness.cpp:73:18: error: 'll' has not been declared
   73 | bool init(int n, ll M, ll a[]){
      |                  ^~
happiness.cpp:73:24: error: 'll' has not been declared
   73 | bool init(int n, ll M, ll a[]){
      |                        ^~
happiness.cpp: In function 'bool init(int, int, int*)':
happiness.cpp:76:2: error: 'mx' was not declared in this scope
   76 |  mx = M;
      |  ^~
happiness.cpp:77:10: error: 'struct Node' has no member named 'sum'
   77 |  tree[1].sum = 0;
      |          ^~~
happiness.cpp:78:10: error: 'struct Node' has no member named 'tl'; did you mean 'l'?
   78 |  tree[1].tl = 1;
      |          ^~
      |          l
happiness.cpp:79:10: error: 'struct Node' has no member named 'tr'; did you mean 'r'?
   79 |  tree[1].tr = 1e12;
      |          ^~
      |          r
happiness.cpp: At global scope:
happiness.cpp:85:29: error: 'll' has not been declared
   85 | bool is_happy(int e, int n, ll a[]){
      |                             ^~
grader.cpp: In function 'int main()':
grader.cpp:16:12: warning: unused variable 'max_code' [-Wunused-variable]
   16 |  long long max_code;
      |            ^~~~~~~~