답안 #287035

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
287035 2020-08-31T09:38:28 Z dolphingarlic Happiness (Balkan15_HAPPINESS) C++14
컴파일 오류
0 ms 0 KB
#include "happiness.h"

#include <utility>

struct Node {
    long long l, r, sm, mn;
    Node *lc, *rc;

    Node(long long L, long long R): l(L), r(R), sm(0), mn(-R), lc(nullptr), rc(nullptr) {}

    void update(long long p, long long v) {
        sm += v;
        if (l != r) {
            long long mid = (l + r) / 2;
            if (p > mid) {
                if (!rc) rc = new Node(mid + 1, r);
                rc->update(p, v);
            } else {
                if (!lc) lc = new Node(l, mid);
                lc->update(p, v);    
            }
            long long lmn = (lc ? lc->mn : -mid), rmn = (rc ? rc->mn : -r);
            long long lsm = (lc ? lc->sm : 0);
            mn = (lmn < lsm + rmn ? lmn : lsm + rmn);
        }
    }

    std::pair<long long, long long> query(long long p) {
        if (r <= p) return std::{sm, mn};
        long long mid = (l + r) / 2;
        if (p > mid) {
            std::pair<int, int> lq = (lc ? lc->query(p) : std::{0, 0}), rq = (rc ? rc->query(p) : std::{0, 0});
            return std::{lq.first + rq.first, (lq.second < lq.first + rq.second ? lq.second : lq.first + rq.second)};
        }
        return (lc ? lc->query(p) : std::{0, 0});
    }
} *root;

bool init(int coinsCount, long long maxCoinSize, long long coins[]) {
    root = new Node(1, maxCoinSize);
    for (int i = 0; i < coinsCount; i++) root->update(coins[i], coins[i]);
	return root->query(root->sm).first < -1;
}

bool is_happy(int event, int coinsCount, long long coins[]) {
	for (int i = 0; i < coinsCount; i++) root->update(coins[i], event * coins[i]);
    return root->query(root->sm).first < -1;
}

Compilation message

happiness.cpp: In member function 'std::pair<long long int, long long int> Node::query(long long int)':
happiness.cpp:29:33: error: expected unqualified-id before '{' token
   29 |         if (r <= p) return std::{sm, mn};
      |                                 ^
happiness.cpp:29:31: error: expected ';' before '{' token
   29 |         if (r <= p) return std::{sm, mn};
      |                               ^ ~
      |                               ;
happiness.cpp:29:9: warning: this 'if' clause does not guard... [-Wmisleading-indentation]
   29 |         if (r <= p) return std::{sm, mn};
      |         ^~
happiness.cpp:29:33: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'if'
   29 |         if (r <= p) return std::{sm, mn};
      |                                 ^
happiness.cpp:29:34: warning: left operand of comma operator has no effect [-Wunused-value]
   29 |         if (r <= p) return std::{sm, mn};
      |                                  ^~
happiness.cpp:29:40: error: expected ';' before '}' token
   29 |         if (r <= p) return std::{sm, mn};
      |                                        ^
      |                                        ;
happiness.cpp:29:38: warning: right operand of comma operator has no effect [-Wunused-value]
   29 |         if (r <= p) return std::{sm, mn};
      |                                      ^~
happiness.cpp:32:64: error: expected unqualified-id before '{' token
   32 |             std::pair<int, int> lq = (lc ? lc->query(p) : std::{0, 0}), rq = (rc ? rc->query(p) : std::{0, 0});
      |                                                                ^
happiness.cpp:32:62: error: expected ')' before '{' token
   32 |             std::pair<int, int> lq = (lc ? lc->query(p) : std::{0, 0}), rq = (rc ? rc->query(p) : std::{0, 0});
      |                                      ~                       ^ ~
      |                                                              )
happiness.cpp:32:110: error: expected ',' or ';' before ')' token
   32 |             std::pair<int, int> lq = (lc ? lc->query(p) : std::{0, 0}), rq = (rc ? rc->query(p) : std::{0, 0});
      |                                                                                                              ^
happiness.cpp:33:25: error: expected unqualified-id before '{' token
   33 |             return std::{lq.first + rq.first, (lq.second < lq.first + rq.second ? lq.second : lq.first + rq.second)};
      |                         ^
happiness.cpp:33:23: error: expected ';' before '{' token
   33 |             return std::{lq.first + rq.first, (lq.second < lq.first + rq.second ? lq.second : lq.first + rq.second)};
      |                       ^ ~
      |                       ;
happiness.cpp:33:37: error: 'rq' was not declared in this scope; did you mean 'r'?
   33 |             return std::{lq.first + rq.first, (lq.second < lq.first + rq.second ? lq.second : lq.first + rq.second)};
      |                                     ^~
      |                                     r
happiness.cpp:35:42: error: expected unqualified-id before '{' token
   35 |         return (lc ? lc->query(p) : std::{0, 0});
      |                                          ^
happiness.cpp:35:40: error: expected ')' before '{' token
   35 |         return (lc ? lc->query(p) : std::{0, 0});
      |                ~                       ^ ~
      |                                        )
happiness.cpp:35:48: error: expected ';' before ')' token
   35 |         return (lc ? lc->query(p) : std::{0, 0});
      |                                                ^
      |                                                ;
happiness.cpp:35:48: error: expected primary-expression before ')' token
grader.cpp: In function 'int main()':
grader.cpp:16:12: warning: unused variable 'max_code' [-Wunused-variable]
   16 |  long long max_code;
      |            ^~~~~~~~