답안 #978107

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
978107 2024-05-08T19:57:19 Z vjudge1 Deda (COCI17_deda) C++17
80 / 140
1000 ms 7692 KB
#include <bits/stdc++.h>
//#include <ext/pb_ds/assoc_container.hpp> // Common file
//#include <ext/pb_ds/tree_policy.hpp> // Including
// tree_order_statistics_node_update #include
//<ext/pb_ds/detail/standard_policies.hpp>
#define S second
#define F first
#define vll vector<ll>
#define pll pair<ll, ll>
#define mll vector<vll>
#define sll set<ll>
#define vstring vector<string>
#define rep(x, g, y) for (ll x = g; x < y; x++)
#define rrep(x, g, y) for (ll x = g; x >= y; x--)
#define all(a) (a).begin(), (a).end()
using namespace std;
// using namespace __gnu_pbds;
// using namespace __gnu_cxx;
typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
// CRAM DEJA DE VER MIS ENVIOS MALDITO
// SUPER SET
// typedef tree<int, null_type, less<int>, rb_tree_tag,
// tree_order_statistics_node_update> ordered_set;

// SUPER MULTISET
// typedef tree<long long, null_type, less_equal<>, rb_tree_tag,
// tree_order_statistics_node_update> indexed_multiset;

// USOS
//  imprimer la cantidad de elementos escritamente menor a X
//   cout << aux.order_of_key(x)<<"\n";

// imprime el elemento k-esimo mas grande(comenzando desde 0)
// cout<<*X.find_by_order(K)<<endl;

// TIP: lower y upper invertidos en multiset.

// ll mod=1e9+7;
//  ll expo(ll a, ll b)
//  {
//      if(a==0) return b==0;
//      ll ans=1;
//      while (b)
//      {
//          if(b&1) ans=(ans*a)%mod;
//          b>>=1LL;
//          a=(a*a)%mod;
//      }
//      return ans;

// }

ll lcm(ll a, ll b) { return (a * b) / __gcd(a, b); }

void yes() { cout << "YES\n"; }

void no() { cout << "NO\n"; }

template <class T> void print_v(vector<T> &v) {
  cout << "{";
  for (auto x : v)
    cout << x << ",";
  cout << "\b}\n";
}
void update(vll &st, ll l, ll r, ll nd, ll pos, ll valor) {
  ll mid = (l + r) / 2;
  if (l == r) {
    st[nd] = valor;
    return;
  }
  if (pos <= mid)
    update(st, l, mid, nd * 2, pos, valor);
  else
    update(st, mid + 1, r, nd * 2 + 1, pos, valor);
  st[nd] = min(st[nd * 2], st[nd * 2 + 1]);
}

ll query(vll &st, ll l, ll r, ll nd, ll lq, ll rq, ll valor) {
  if (valor < st[nd])
    return 1e12;
  ll mid = (l + r) / 2;
  if(lq>r) return 1e12;
  if (l == r )
    return l + 1;


    return min(query(st, l, mid, nd * 2, lq, rq, valor),query(st, mid + 1, r, nd * 2+1, lq, rq, valor));

}
void solve() {
  ll n, q;
  cin >> n >> q;
  vll st(4*n,1e12);
  while (q--) {
    char x;
    cin >> x;
    ll a, b;
    cin >> a >> b;
    if (x == 'M')
    {
        //cout << a<<"\n";
        update(st, 0, n - 1, 1, --b, a);
    }

    else
    {
        ll ans=query(st, 0, n - 1, 1, --b, n-1, a);
        if(ans>=1e12) ans=-1;
        cout <<ans<<"\n";
    }

    //print_v(st);
  }
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);

  // ll t; cin >> t;
  // while(t--)
  solve();

  return 0;
}

Compilation message

deda.cpp: In function 'll query(std::vector<long long int>&, ll, ll, ll, ll, ll, ll)':
deda.cpp:85:3: warning: this 'if' clause does not guard... [-Wmisleading-indentation]
   85 |   if (l == r )
      |   ^~
deda.cpp:89:5: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'if'
   89 |     return min(query(st, l, mid, nd * 2, lq, rq, valor),query(st, mid + 1, r, nd * 2+1, lq, rq, valor));
      |     ^~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 6 ms 348 KB Output is correct
4 Correct 367 ms 7692 KB Output is correct
5 Execution timed out 1067 ms 3936 KB Time limit exceeded
6 Execution timed out 1016 ms 5292 KB Time limit exceeded
7 Execution timed out 1053 ms 6812 KB Time limit exceeded