제출 #1306383

#제출 시각아이디문제언어결과실행 시간메모리
1306383iamsazidhDeda (COCI17_deda)C++20
140 / 140
576 ms4556 KiB
//ᴇᴀᴄʜ ᴘᴇʀꜱᴏɴ ᴡɪʟʟ ᴏɴʟʏ ʜᴀᴠᴇ ᴡʜᴀᴛ ᴛʜᴇʏ ᴇɴᴅᴇᴀᴠᴏᴜʀᴇᴅ ᴛᴏᴡᴀʀᴅꜱ [53:39] //Author: Sazid Hasan #include <bits/stdc++.h> using namespace std; typedef long long ll; typedef double dl; typedef vector<int> vi; typedef vector<vector<int>> vii; typedef vector<ll> vl; typedef vector<bool> vb; typedef pair<int,int> pii; typedef pair<ll, ll> pll; #define ff first #define ss second #define all(a) a.begin(),a.end() #define gcd(a,b) __gcd(a,b) #define lcm(a,b) (a*(b/gcd(a,b))) #define file(); freopen("input.txt", "r", stdin);freopen("output.txt", "w", stdout); #define spc " " #ifdef ONLINE_JUDGE #define debarr(array) #define deb(x) #define del #define debug(...) #else #define debarr(array) for(int w = 0; w < array.size(); w++) cerr << #array << "-" << w << " = " << array[w] << endl; #define deb(x) cerr << #x << " = " << x << endl; #define del cerr << '\n'; #define debug(...) _debug(#__VA_ARGS__, __VA_ARGS__); template <class X, class Y> ostream& operator<<(ostream& os, const pair<X, Y>& p) { return os << "(" << p.first << ", " << p.second << ")"; } template <class Ch, class Tr, class Container> basic_ostream<Ch, Tr>& operator<<(basic_ostream<Ch, Tr>& os, const Container& x) { int i = 0, n = distance(x.begin(), x.end()); os << "{ "; for (const auto& y : x) os << y << (++i < n ? ", " : ""); return os << " }"; } template <typename... Args> void _debug(const char* names, Args&&... args) { string_view s(names); cerr << "{ "; size_t i = 0, cnt = 0, n = sizeof...(args); auto next = [&]() { while (i < s.size() && (s[i] == ' ' || s[i] == ',')) ++i; size_t st = i; while (i < s.size() && s[i] != ',') ++i; return s.substr(st, i - st); }; ((cerr << next() << ": " << args << (++cnt < n ? ", " : "")), ...); cerr << " }" << '\n'; } #endif const double PI = acos(-1); const int MOD = 1000000007; const int inf = (2147483647); const double EPS = 1e-6; const int MAXN = 1e5+10; class segTree{ private: vi tr; int n; public: segTree(int _n){ n = _n; tr.resize((n+3)*4, inf); } void update(int x, int lx, int rx, int idx, int v){ if(lx==rx){ tr[x] = v; }else{ int m = (lx+rx)/2; if(idx<=m) update(x*2+1, lx, m, idx, v); else update(x*2+2, m+1, rx, idx, v); tr[x] = min(tr[x*2+1], tr[x*2+2]); } return; } int query(int x, int lx, int rx, int l, int r){ if(lx>r || rx<l) return inf; if(lx>= l && rx<=r) return tr[x]; int m = (lx+rx)>>1; return min(query(x*2+1, lx, m, l, r), query(x*2+2, m+1, rx, l, r)); } void update(int idx, int v){ update(0, 0, n, idx, v); } int query(int l, int r){ return query(0, 0, n, l, r); } }; bool solve(){ int n, q; cin >> n >> q; segTree tr(n); while(q--){ char c; cin >> c; if(c=='M'){ int age, station; cin >> station >> age; tr.update(age, station); }else{ int stop, child; cin >> stop >> child; if(tr.query(child, n)>stop){ cout << -1 << endl; }else{ int st = child, end = n, mid; while(st<=end){ mid = (st+end) >> 1; if(tr.query(child, mid)<=stop) end = mid-1; else st = mid+1; } cout << st << endl; } } } return 1; } int main(){ ios::sync_with_stdio(false); cin.tie(nullptr); int testcase = 1; //cin >> testcase; for(int tc = 1; tc <= testcase; tc++){ //cerr << "TESTCASE - " << tc << endl; solve(); //cout << (solve() ? "YES" : "NO") << '\n'; cerr << endl; } return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...