제출 #685091

#제출 시각아이디문제언어결과실행 시간메모리
685091vovamrRestore Array (RMI19_restore)C++17
45 / 100
99 ms640 KiB
#include <bits/stdc++.h> #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> #define fi first #define se second #define ll long long #define ld long double #define sz(x) ((int)(x).size()) #define all(x) (x).begin(), (x).end() #define pb push_back #define mpp make_pair #define ve vector using namespace std; using namespace __gnu_pbds; template<class T> using oset = tree<T,null_type,less<T>,rb_tree_tag,tree_order_statistics_node_update>; const ll inf = 1e18; const int iinf = 1e9; typedef pair<ll, ll> pll; typedef pair<int, int> pii; mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count()); template <typename T> inline bool chmin(T& a, T b) { return (a > b ? a = b, 1 : 0); } template <typename T> inline bool chmax(T& a, T b) { return (a < b ? a = b, 1 : 0); } const int N = 5e3 + 10; int n; int a[N]; inline void build() { for (int i = 0; i < n; ++i) { a[i] = -1; } } inline array<int,3> get(int l, int r) { int s = 0, mn = iinf, cmn = 0; for (int i = l; i <= r; ++i) { s += a[i]; if (mn == a[i]) ++cmn; else if (mn > a[i]) mn = a[i], cmn = 1; } return {s, mn, cmn}; } inline void upd(int l, int r, int x) { for (int i = l; i <= r; ++i) { a[i] = x; } } inline void solve() { int m; cin >> n >> m; ve<array<int,4>> e(m); for (auto &[l, r, k, x] : e) cin >> l >> r >> k >> x; sort(all(e)); if (n <= 18) { ve<int> pf(n); for (int ma = 0; ma < (1 << n); ++ma) { for (int i = 0; i < n; ++i) { pf[i] = ma >> i & 1 ^ 1; if (i) pf[i] += pf[i - 1]; } bool ok = 1; for (auto &[l, r, k, x] : e) { int s = pf[r] - (!l ? 0 : pf[l - 1]); ok &= (x == (s >= k ? 0 : 1)); } if (ok) { for (int i = 0; i < n; ++i) { cout << !(pf[i] - (!i ? 0 : pf[i - 1])) << " "; } return; } } cout << -1; return; } build(); for (auto &[l, r, k, x] : e) { if (k == 1 && x == 1) { for (int i = l; i <= r; ++i) { if (a[i] == 0) return void(cout << -1); a[i] = 1; } } else if (k == r - l + 1 && !x) { for (int i = l; i <= r; ++i) { if (a[i] == 1) return void(cout << -1); a[i] = 0; } } } for (auto &[l, r, k, x] : e) { if (k == 1 && x == 0) { bool ok = 0; for (int i = l; i <= r; ++i) { if (a[i] == 0) { ok = 1; break; } } if (!ok) { for (int i = l; i <= r; ++i) { if (a[i] == -1) { a[i] = 0; ok = 1; break; } } } if (!ok) return void(cout << -1); } else if (k == r - l + 1 && x == 1) { bool ok = 0; for (int i = l; i <= r; ++i) { if (a[i] == 1) { ok = 1; break; } } if (!ok) { for (int i = l; i <= r; ++i) { if (a[i] == -1) { a[i] = 1; ok = 1; break; } } } if (!ok) return void(cout << -1); } } for (int i = 0; i < n; ++i) if (a[i] == -1) a[i] = 0; for (int i = 0; i < n; ++i) cout << a[i] << " "; } signed main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); int q = 1; // cin >> q; while (q--) solve(); cerr << fixed << setprecision(3) << "Time execution: " << (double)clock() / CLOCKS_PER_SEC << endl; }

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

restore.cpp: In function 'void solve()':
restore.cpp:59:21: warning: suggest parentheses around arithmetic in operand of '^' [-Wparentheses]
   59 |     pf[i] = ma >> i & 1 ^ 1;
      |             ~~~~~~~~^~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...