Submission #1177106

#TimeUsernameProblemLanguageResultExecution timeMemory
1177106InvMODDeda (COCI17_deda)C++20
140 / 140
512 ms4616 KiB
#include <bits/stdc++.h> using namespace std; #define fi first #define se second #define gcd __gcd #define sz(v) (int) v.size() #define pb push_back #define pi pair<int,int> #define all(v) (v).begin(), (v).end() #define compact(v) (v).erase(unique(all(v)), (v).end()) #define FOR(i, a, b) for(int i = (a); i <= (b); i++) #define REV(i, a, b) for(int i = (a); i >= (b); i--) #define dbg(x) "[" #x " = " << (x) << "]" ///#define int long long using ll = long long; using ld = long double; using ull = unsigned long long; template<typename T> bool ckmx(T& a, const T& b){if(a < b) return a = b, true; return false;} template<typename T> bool ckmn(T& a, const T& b){if(a > b) return a = b, true; return false;} const int N = 2e5+5; const ll MOD = 1e9+7; const ll INF = 1e18; struct SMT{ int trsz; vector<int> st; SMT(int n = 0): trsz(n), st((n << 2) | 1, 1e9 + 7) {} void update(int id, int l, int r, int x, int val){ if(l == r){ st[id] = val; } else{ int m = l+r>>1; if(x <= m) update(id << 1, l, m, x, val); else update(id << 1|1, m+1, r, x, val); st[id] = min(st[id << 1], st[id << 1|1]); } } int query(int id, int l, int r, int u, int v){ if(l > v || r < u) return 1e9 + 7; if(l >= u && r <= v) return st[id]; int m = l+r>>1; return min(query(id << 1, l, m, u, v), query(id << 1|1, m+1, r, u, v)); } int query(int l, int r){ return query(1, 1, trsz, l, r); } void update(int x, int val){ update(1, 1, trsz, x, val); } }; void solve() { int n,q; cin >> n >> q; SMT st(n); auto find_answer = [&](int start, int target) -> int{ int l = start - 1, r = n + 1; while(l + 1 < r){ int m = l+r>>1; if(st.query(start, m) <= target){ r = m; } else l = m; } return (r == n + 1 ? -1 : r); }; while(q--){ char op; cin >> op; if(op == 'M'){ int x,a; cin >> x >> a; st.update(a, x); } else{ int y,b; cin >> y >> b; cout << find_answer(b, y) << "\n"; } } } signed main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); #define name "InvMOD" if(fopen(name".INP", "r")){ freopen(name".INP","r",stdin); freopen(name".OUT","w",stdout); } int t = 1; //cin >> t; while(t--) solve(); return 0; }

Compilation message (stderr)

deda.cpp: In function 'int main()':
deda.cpp:107:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
  107 |         freopen(name".INP","r",stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~
deda.cpp:108:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
  108 |         freopen(name".OUT","w",stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...