제출 #995104

#제출 시각아이디문제언어결과실행 시간메모리
995104ds5105119괄호 문자열 (kriii3_R)C++17
0 / 113
10058 ms15144 KiB
#include <iostream> #include <vector> #include <queue> #include <algorithm> #include <cmath> using namespace std; typedef long long ll; ll modpow(ll b, ll e, ll m) { b %= m; ll ret = 1; while (e > 0) { if (e & 1) ret = (ret * b) % m; b = (b * b) % m; e >>= 1; } return ret; } vector<ll> mod_catalan(vector<ll> queries, ll m) { vector<ll> catalans = {1}; vector<ll> results; ll val = 0; ll idx = 0; if (queries.empty()) { return queries; } for (ll n = 0; n <= queries.back(); n++) { while (n == queries[idx]) { results.push_back(catalans.back()); idx++; } for (int i = 0; i <= n; i++) { val += catalans[i] * catalans[n - i] % m; } catalans.push_back(val % m); val = 0; } return catalans; } vector<ll> get_a(vector<ll> queries, ll m) { vector<ll> even_val; vector<ll> catalans; ll val = 0; ll idx = 0; int len = (int)queries.size(); for(ll i: queries) { if (i % 2 == 0) { even_val.push_back(i / 2ll); } } catalans = mod_catalan(even_val, m); for (int i = 0; i < len; i++) { val = modpow(2ll, queries[i], m); if (queries[i] % 2 == 0) { val -= catalans[idx]; val %= m; idx++; } queries[i] = val; } return queries; } vector<ll> get_b(vector<ll> queries, ll m) { vector<ll> b_l; deque<ll> b_q = {}; ll b_i = 1; ll idx = 0; ll mid = queries.back() / 2ll + 1ll; for (int i = 1; i <= queries.back(); i++) { if (i % 2) { b_i = (2ll * b_i) % m; } else { b_i = (2ll * b_i - b_q.front()) % m; b_q.pop_front(); } if (i < mid) { b_q.push_back(b_i); } while (i == queries[idx]) { b_l.push_back(b_i); idx++; } } return b_l; } vector<ll> get_c(vector<ll> queries, ll m) { vector<ll> even_range; vector<ll> catalans; vector<ll> a_l; vector<ll> c_l = get_b(queries, m); ll a; ll even_max = 0; for (ll i : queries) { if (i % 2 == 0) { even_max = i; } } for (ll i = 0; i <= even_max / 2ll; i++) even_range.push_back(i); catalans = mod_catalan(even_range, m); for (ll i = 0; i <= even_max / 2ll; i++) { a = catalans[i]; for (ll j = 1; j <= i / 2ll; j++) { a -= (catalans[i - 2ll * j] * a_l[j]) % m; a %= m; } a_l.push_back(a); } for (ll i = 0; i < c_l.size(); i++) { if (queries[i] % 2 == 0) { c_l[i] -= a_l[queries[i] / 2ll]; c_l[i] %= m; } } return c_l; } int test() { vector<ll> result1; vector<ll> result2; vector<ll> result3; vector<ll> result4; vector<ll> idx; vector<ll> queries; ll m = 1000000; // 쿼리 설정 for (int i = 1; i < 1000; i++) { queries.push_back(i); queries.push_back(i); } vector<ll> result(queries.size()); for (ll i = 0; i < queries.size(); i++) { idx.push_back(i); } sort(idx.begin(), idx.end(), [&queries](size_t i, size_t j) { return queries[i] < queries[j]; }); sort(queries.begin(), queries.end()); result1 = mod_catalan(queries, m); result2 = get_a(queries, m); result3 = get_b(queries, m); result4 = get_c(queries, m); cout << "catalans" << endl; for (int i = 0; i < queries.size(); i++) { result[idx[i]] = result1[i]; if (result[idx[i]] < 0) { result[idx[i]] += m; } } for (ll i : result) { cout << i << " "; } cout << endl; cout << "a" << endl; for (int i = 0; i < queries.size(); i++) { result[idx[i]] = result2[i]; if (result[idx[i]] < 0) { result[idx[i]] += m; } } for (ll i : result) { cout << i << " "; } cout << endl; cout << "b" << endl; for (int i = 0; i < queries.size(); i++) { result[idx[i]] = result3[i]; if (result[idx[i]] < 0) { result[idx[i]] += m; } } for (ll i : result) { cout << i << " "; } cout << endl; cout << "c" << endl; for (int i = 0; i < queries.size(); i++) { result[idx[i]] = result4[i]; if (result[idx[i]] < 0) { result[idx[i]] += m; } } for (ll i : result) { cout << i << " "; } cout << endl; return 0; } int main() { ll p, q, m, Q, l; vector<ll> queries; vector<ll> result; vector<ll> idx; test(); scanf("%lld %lld %lld %lld", &p, &q, &m, &Q); for (int i = 0; i < Q; i++) { scanf("%lld", &l); queries.push_back(l); idx.push_back(i); } sort(idx.begin(), idx.end(), [&queries](size_t i, size_t j) { return queries[i] < queries[j]; }); sort(queries.begin(), queries.end()); if (p == 1 && q == 0) { result = get_a(queries, m); } else if (p == 0 && q == 1) { result = get_b(queries, m); } else if (p == 1 && q == 1) { result = get_c(queries, m); } else { return 0; } for (int i = 0; i < Q; i++) { queries[idx[i]] = result[i]; if (queries[idx[i]] < 0) { queries[idx[i]] += m; } } for (ll i : queries) { cout << i << endl; } return 0; }

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

R.cpp: In function 'std::vector<long long int> get_c(std::vector<long long int>, ll)':
R.cpp:133:22: warning: comparison of integer expressions of different signedness: 'll' {aka 'long long int'} and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  133 |     for (ll i = 0; i < c_l.size(); i++) {
      |                    ~~^~~~~~~~~~~~
R.cpp: In function 'int test()':
R.cpp:160:22: warning: comparison of integer expressions of different signedness: 'll' {aka 'long long int'} and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  160 |     for (ll i = 0; i < queries.size(); i++) {
      |                    ~~^~~~~~~~~~~~~~~~
R.cpp:175:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  175 |     for (int i = 0; i < queries.size(); i++) {
      |                     ~~^~~~~~~~~~~~~~~~
R.cpp:187:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  187 |     for (int i = 0; i < queries.size(); i++) {
      |                     ~~^~~~~~~~~~~~~~~~
R.cpp:199:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  199 |     for (int i = 0; i < queries.size(); i++) {
      |                     ~~^~~~~~~~~~~~~~~~
R.cpp:211:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  211 |     for (int i = 0; i < queries.size(); i++) {
      |                     ~~^~~~~~~~~~~~~~~~
R.cpp: In function 'int main()':
R.cpp:232:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
  232 |     scanf("%lld %lld %lld %lld", &p, &q, &m, &Q);
      |     ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
R.cpp:235:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
  235 |         scanf("%lld", &l);
      |         ~~~~~^~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...