Submission #1084697

#TimeUsernameProblemLanguageResultExecution timeMemory
1084697KasymKBridges (APIO19_bridges)C++17
0 / 100
3044 ms5280 KiB
#include "bits/stdc++.h" using namespace std; #define ff first #define ss second #define all(v) v.begin(), v.end() #define ll long long #define pb push_back #define pii pair<int, int> #define pli pair<ll, int> #define pll pair<ll, ll> #define tr(i, c) for(auto i = c.begin(); i != c.end(); ++i) #define wr puts("----------------") template<class T>bool umin(T& a,T b){if(a>b){a=b;return 1;}return 0;} template<class T>bool umax(T& a,T b){if(a<b){a=b;return 1;}return 0;} const int N = 5e4+5; struct node{ int val, l, r; } seg[N<<2]; int v[N]; void build(int x, int l, int r){ seg[x].l = l, seg[x].r = r; if(l == r){ seg[x].val = v[l]; return; } int mid = (l+r)>>1; build(x<<1, l, mid); build(x<<1|1, mid+1, r); seg[x].val = min(seg[x<<1].val, seg[x<<1|1].val); } void update(int x, int k, int u){ // if(seg[x].l == seg[x].r){ // seg[x].val = u; // return; // } // int mid = (seg[x].l+seg[x].r)>>1; // if(k <= mid) // update(x<<1, k, u); // else // update(x<<1|1, k, u); // seg[x].val = min(seg[x<<1].val, seg[x<<1|1].val); v[k] = u; return; } int query(int x, int l, int r){ if(l > r) return 0; // if(seg[x].l == l and seg[x].r == r) // return seg[x].val; // int mid = (seg[x].l+seg[x].r)>>1; // if(r <= mid) // return query(x<<1, l, r); // else if(l > mid) // return query(x<<1|1, l, r); // else // return min(query(x<<1, l, mid), query(x<<1|1, mid+1, r)); int mn = 1e9; for(int i = l; i <= r; ++i) umin(mn, v[i]); return mn; } int main(){ // freopen("file.txt", "r", stdin); int n, m; scanf("%d%d", &n, &m); for(int i = 1; i <= m; ++i){ int a, b, x; scanf("%d%d%d", &a, &b, &x); v[i] = x; } build(1, 1, n); int q; scanf("%d", &q); while(q--){ int op; scanf("%d", &op); if(op == 1){ int b, r; scanf("%d%d", &b, &r); update(1, b, r); continue; } // op = 2 int s, w; scanf("%d%d", &s, &w); int l = 1, r = s, ans = 1e9; while(l <= r){ int mid = (l+r)>>1; int mn = query(1, mid, s-1); if(mn < w) l = mid+1; else r = mid-1, ans = mid; } int ans1 = 0; l = s, r = m; while(l <= r){ int mid = (l+r)>>1; int mn = query(1, s, mid); if(mn < w) r = mid-1; else l = mid+1, ans1 = mid; } int answer = 0; if(ans1 > s) ans1++; if(ans1 > s) answer += ans1-s; if(ans < s) answer += s-ans; printf("%d\n", answer+1); } return 0; }

Compilation message (stderr)

bridges.cpp: In function 'int main()':
bridges.cpp:71:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   71 |     scanf("%d%d", &n, &m);
      |     ~~~~~^~~~~~~~~~~~~~~~
bridges.cpp:74:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   74 |         scanf("%d%d%d", &a, &b, &x);
      |         ~~~~~^~~~~~~~~~~~~~~~~~~~~~
bridges.cpp:79:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   79 |     scanf("%d", &q);
      |     ~~~~~^~~~~~~~~~
bridges.cpp:82:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   82 |         scanf("%d", &op);
      |         ~~~~~^~~~~~~~~~~
bridges.cpp:85:18: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   85 |             scanf("%d%d", &b, &r);
      |             ~~~~~^~~~~~~~~~~~~~~~
bridges.cpp:91:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   91 |         scanf("%d%d", &s, &w);
      |         ~~~~~^~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...