제출 #697358

#제출 시각아이디문제언어결과실행 시간메모리
697358Do_you_copyIzbori (COCI22_izbori)C++17
컴파일 에러
0 ms0 KiB
/* I find it wholesome to be alone the greater part of the time. To be in company, even with the best, is soon wearisome and dissipating. I love to be alone. I never found the companion that was so companionable as solitude. */ #include <bits/stdc++.h> #define pb push_back #define fi first #define se second #define faster ios_base::sync_with_stdio(0); cin.tie(0); #define int long long using namespace std; using ll = long long; using ld = long double; using pii = pair <int, int>; mt19937_64 Rand(chrono::steady_clock::now().time_since_epoch().count()); const int maxN = 1e5 + 1; //const int Mod = 1e9 + 7; //const ll inf = 0x3f3f3f3f3f3f3f3f; int n; vector <int> S[maxN]; int a[maxN]; int dp[maxN]; ll ans; ll calc(int i, int j, int k){ int l = k - i; int r = k ; k = max(0, r - max(j + 1, l - 1)); l = max(l, 0); r = min(r, j + 1); if (l > r) return k * (j + 1); return 1LL * (l + r) * (r - l + 1) / 2 + k * (j + 1); } void Light(int c){ for (int i = 0; i < signed(S[c].size()); ++i){ for (int j = i; j < signed(S[c].size()); ++j){ int l = i ? S[c][i - 1] : 0; int r = (j + 1 == S[c].size()) ? n + 1 : S[c][j + 1]; int k = (j - i + 1) - (S[c][j] - S[c][i] - j + i); ans += calc(S[c][i] - l - 1, r - S[c][j] - 1, k); } } } void Heavy(int c){ fill(dp, dp + 2 * n + 2, 0); int cur = n + 1; dp[cur] = 1; for (int i = 1; i <= n; ++i){ if (a[i] == c){ ++cur; dp[cur] += dp[cur - 1]; } else{ dp[cur] -= dp[cur - 1]; --cur; } ++dp[cur]; ans += dp[cur - 1]; } } void Init(){ cin >> n; vector <int> node; for (int i = 1; i <= n; ++i){ cin >> a[i]; node.pb(a[i]); } sort(node.begin(), node.end()); node.resize(unique(node.begin(), node.end()) - node.begin()); for (int i = 1; i <= n; ++i){ a[i] = upper_bound(node.begin(), node.end(), a[i]) - node.begin(); S[a[i]].pb(i); } for (int i = 1; i <= n; ++i){ if (S[i].empty()) continue; if (S[i].size() <= 318) Light(i); else Heavy(i); } cout << ans; } #define debug #define taskname "test" signed main(){ faster if (fopen(taskname".inp", "r")){ freopen(taskname".inp", "r", stdin); freopen(taskname".out", "w", stdout); } int tt = 1; //cin >> tt; while (tt--){ Init(); } if (fopen("timeout.txt", "r")){ ofstream timeout("timeout.txt"); timeout << signed(double(clock()) / CLOCKS_PER_SEC * 1000); timeout.close(); #ifndef debug cerr << "Time elapsed: " << signed(double(clock()) / CLOCKS_PER_SEC * 1000) << "ms\n"; #endif // debug } }

컴파일 시 표준 에러 (stderr) 메시지

Main.cpp: In function 'll calc(long long int, long long int, long long int)':
Main.cpp:30:37: error: no matching function for call to 'max(int, long long int)'
   30 |     k = max(0, r - max(j + 1, l - 1));
      |                                     ^
In file included from /usr/include/c++/10/bits/specfun.h:45,
                 from /usr/include/c++/10/cmath:1927,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:41,
                 from Main.cpp:7:
/usr/include/c++/10/bits/stl_algobase.h:254:5: note: candidate: 'template<class _Tp> constexpr const _Tp& std::max(const _Tp&, const _Tp&)'
  254 |     max(const _Tp& __a, const _Tp& __b)
      |     ^~~
/usr/include/c++/10/bits/stl_algobase.h:254:5: note:   template argument deduction/substitution failed:
Main.cpp:30:37: note:   deduced conflicting types for parameter 'const _Tp' ('int' and 'long long int')
   30 |     k = max(0, r - max(j + 1, l - 1));
      |                                     ^
In file included from /usr/include/c++/10/bits/specfun.h:45,
                 from /usr/include/c++/10/cmath:1927,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:41,
                 from Main.cpp:7:
/usr/include/c++/10/bits/stl_algobase.h:300:5: note: candidate: 'template<class _Tp, class _Compare> constexpr const _Tp& std::max(const _Tp&, const _Tp&, _Compare)'
  300 |     max(const _Tp& __a, const _Tp& __b, _Compare __comp)
      |     ^~~
/usr/include/c++/10/bits/stl_algobase.h:300:5: note:   template argument deduction/substitution failed:
Main.cpp:30:37: note:   deduced conflicting types for parameter 'const _Tp' ('int' and 'long long int')
   30 |     k = max(0, r - max(j + 1, l - 1));
      |                                     ^
In file included from /usr/include/c++/10/algorithm:62,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:65,
                 from Main.cpp:7:
/usr/include/c++/10/bits/stl_algo.h:3480:5: note: candidate: 'template<class _Tp> constexpr _Tp std::max(std::initializer_list<_Tp>)'
 3480 |     max(initializer_list<_Tp> __l)
      |     ^~~
/usr/include/c++/10/bits/stl_algo.h:3480:5: note:   template argument deduction/substitution failed:
Main.cpp:30:37: note:   mismatched types 'std::initializer_list<_Tp>' and 'int'
   30 |     k = max(0, r - max(j + 1, l - 1));
      |                                     ^
In file included from /usr/include/c++/10/algorithm:62,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:65,
                 from Main.cpp:7:
/usr/include/c++/10/bits/stl_algo.h:3486:5: note: candidate: 'template<class _Tp, class _Compare> constexpr _Tp std::max(std::initializer_list<_Tp>, _Compare)'
 3486 |     max(initializer_list<_Tp> __l, _Compare __comp)
      |     ^~~
/usr/include/c++/10/bits/stl_algo.h:3486:5: note:   template argument deduction/substitution failed:
Main.cpp:30:37: note:   mismatched types 'std::initializer_list<_Tp>' and 'int'
   30 |     k = max(0, r - max(j + 1, l - 1));
      |                                     ^
Main.cpp:31:17: error: no matching function for call to 'max(long long int&, int)'
   31 |     l = max(l, 0);
      |                 ^
In file included from /usr/include/c++/10/bits/specfun.h:45,
                 from /usr/include/c++/10/cmath:1927,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:41,
                 from Main.cpp:7:
/usr/include/c++/10/bits/stl_algobase.h:254:5: note: candidate: 'template<class _Tp> constexpr const _Tp& std::max(const _Tp&, const _Tp&)'
  254 |     max(const _Tp& __a, const _Tp& __b)
      |     ^~~
/usr/include/c++/10/bits/stl_algobase.h:254:5: note:   template argument deduction/substitution failed:
Main.cpp:31:17: note:   deduced conflicting types for parameter 'const _Tp' ('long long int' and 'int')
   31 |     l = max(l, 0);
      |                 ^
In file included from /usr/include/c++/10/bits/specfun.h:45,
                 from /usr/include/c++/10/cmath:1927,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:41,
                 from Main.cpp:7:
/usr/include/c++/10/bits/stl_algobase.h:300:5: note: candidate: 'template<class _Tp, class _Compare> constexpr const _Tp& std::max(const _Tp&, const _Tp&, _Compare)'
  300 |     max(const _Tp& __a, const _Tp& __b, _Compare __comp)
      |     ^~~
/usr/include/c++/10/bits/stl_algobase.h:300:5: note:   template argument deduction/substitution failed:
Main.cpp:31:17: note:   deduced conflicting types for parameter 'const _Tp' ('long long int' and 'int')
   31 |     l = max(l, 0);
      |                 ^
In file included from /usr/include/c++/10/algorithm:62,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:65,
                 from Main.cpp:7:
/usr/include/c++/10/bits/stl_algo.h:3480:5: note: candidate: 'template<class _Tp> constexpr _Tp std::max(std::initializer_list<_Tp>)'
 3480 |     max(initializer_list<_Tp> __l)
      |     ^~~
/usr/include/c++/10/bits/stl_algo.h:3480:5: note:   template argument deduction/substitution failed:
Main.cpp:31:17: note:   mismatched types 'std::initializer_list<_Tp>' and 'long long int'
   31 |     l = max(l, 0);
      |                 ^
In file included from /usr/include/c++/10/algorithm:62,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:65,
                 from Main.cpp:7:
/usr/include/c++/10/bits/stl_algo.h:3486:5: note: candidate: 'template<class _Tp, class _Compare> constexpr _Tp std::max(std::initializer_list<_Tp>, _Compare)'
 3486 |     max(initializer_list<_Tp> __l, _Compare __comp)
      |     ^~~
/usr/include/c++/10/bits/stl_algo.h:3486:5: note:   template argument deduction/substitution failed:
Main.cpp:31:17: note:   mismatched types 'std::initializer_list<_Tp>' and 'long long int'
   31 |     l = max(l, 0);
      |                 ^
Main.cpp: In function 'void Light(long long int)':
Main.cpp:41:28: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   41 |             int r = (j + 1 == S[c].size()) ? n + 1 : S[c][j + 1];
      |                      ~~~~~~^~~~~~~~~~~~~~
Main.cpp: In function 'int main()':
Main.cpp:92:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   92 |         freopen(taskname".inp", "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~
Main.cpp:93:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   93 |         freopen(taskname".out", "w", stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~