Submission #162035

#TimeUsernameProblemLanguageResultExecution timeMemory
162035DifferentHeavenDeda (COCI17_deda)C++17
140 / 140
732 ms9592 KiB
#include <bits/stdc++.h> #define ii pair <int, int> #define x first #define y second #define db(x) cerr << #x << " = " << x << endl; #define _ << " _ " << using namespace std; const int N = 2e5 + 7; const int oo = 1e9 + 7; int n, m; struct segTree{ int tree[N << 3]; segTree() { for (int i = 0; i < (N << 3); i++) tree[i] = oo; } void Update(int x, int l, int r, int i, int j, int val){ if (l > j || r < i) return; if (l >= i && r <= j){ tree[x] = val; return; } int mid = l + r >> 1; Update(2 * x, l, mid, i, j, val); Update(2 * x + 1, mid + 1, r, i, j, val); tree[x] = min(tree[2 * x], tree[2 * x + 1]); } int Find(int x, int l, int r, int i, int j, int val){ if (l > j || r < i) return -1; if (l >= i && r <= j){ while (l < r){ int mid = l + r >> 1; if (tree[2 * x] <= val){ r = mid; x = 2 * x; } else{ l = mid + 1; x = 2 * x + 1; } } if (tree[x] <= val) return r; return -1; } int mid = l + r >> 1; int L = Find(2 * x, l, mid, i, j, val); if (L != -1) return L; int R = Find(2 * x + 1, mid + 1, r, i, j, val); return R; } }IT; int main(){ ios_base::sync_with_stdio(false); cin.tie(nullptr); if(fopen("test.inp", "r")) freopen("test.inp", "r", stdin), freopen("test.out", "w", stdout); cin >> n >> m; for (int i = 1; i <= m; i++){ char ch; int x, y; cin >> ch >> x >> y; if (ch == 'M'){ IT.Update(1, 1, n, y, y, x); } else{ cout << IT.Find(1, 1, n, y, n, x) << endl; } } }

Compilation message (stderr)

deda.cpp: In member function 'void segTree::Update(int, int, int, int, int, int)':
deda.cpp:29:15: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   int mid = l + r >> 1;
             ~~^~~
deda.cpp: In member function 'int segTree::Find(int, int, int, int, int, int)':
deda.cpp:40:17: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
     int mid = l + r >> 1;
               ~~^~~
deda.cpp:54:15: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   int mid = l + r >> 1;
             ~~^~~
deda.cpp: In function 'int main()':
deda.cpp:66:60: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)', declared with attribute warn_unused_result [-Wunused-result]
  if(fopen("test.inp", "r")) freopen("test.inp", "r", stdin), freopen("test.out", "w", stdout);
                             ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
deda.cpp:66:60: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)', declared with attribute warn_unused_result [-Wunused-result]
#Verdict Execution timeMemoryGrader output
Fetching results...