Problem p02348 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < n; i++)
#define rrep(i, n) for (int i = 1; i <= n; i++)
#define drep(i, n) for (int i = n; i >= 0; i--)
#define MAX 100000
#define ll long long
#define dmp make_pair
#define dpb push_back
#define P pair<int, int>
#define fi first
#define se second
using namespace std;
//__gcd(a,b), __builtin_popcount(a);
const int INF = 2147483647;
#define B 100

int bucket[MAX / B][B];
int data[MAX / B];
void update(int a, int b, int x) {
  int f1 = 1, f2 = 1;
  while (a <= b && a % B != 0) {
    if (f1 && data[a / B] != -1) {
      for (int i = 0; i < 100; i++)
        bucket[a / B][i] = data[a / B];
      f1 = 0;
      data[a / B] = -1;
    }
    bucket[a / B][a % B] = x;
    a++;
  }
  while (a <= b && b % B != 99) {
    if (f2 && data[b / B] != -1) {
      for (int i = 0; i < 100; i++)
        bucket[b / B][i] = data[b / B];
      f2 = 0;
      data[b / B] = -1;
    }
    bucket[b / B][b % B] = x;
    b--;
  }
  while (a < b) {
    data[a / B] = x;
    a += B;
  }
}

int find(int x) {
  if (data[x / B] != -1) {
    for (int i = 0; i < 100; i++)
      bucket[x / B][i] = data[x / B];
    data[x / B] = -1;
  }
  return bucket[x / B][x % B];
}

int main() {
  int n, q, c, s, t, x, ans;
  scanf("%d%d", &n, &q);
  fill(data, data + MAX / B, -1);
  fill((int *)bucket, (int *)(bucket + MAX / B), INF);
  while (q--) {
    scanf("%d", &c);
    if (!c) {
      scanf("%d%d%d", &s, &t, &x);
      update(s, t, x);
    } else {
      scanf("%d", &x);
      ans = find(x);
      printf("%d\\n", ans);
    }
  }
  // rep(i,n)printf("%d ", bucket[0][i]);
  return 0;
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < n; i++)
#define rrep(i, n) for (int i = 1; i <= n; i++)
#define drep(i, n) for (int i = n; i >= 0; i--)
#define MAX 100000
#define ll long long
#define dmp make_pair
#define dpb push_back
#define P pair<int, int>
#define fi first
#define se second
using namespace std;
//__gcd(a,b), __builtin_popcount(a);
const int INF = 2147483647;
#define B 100

int bucket[MAX / B][B];
int udata[MAX / B], data[MAX / B];
void update(int a, int b, int x) {
  int f1 = 1, f2 = 1;
  while (a <= b && a % B != 0) {
    if (f1 && udata[a / B] != -1) {
      for (int i = 0; i < MAX; i++)
        bucket[a / B][i] = udata[a / B];
      f1 = 0;
      udata[a / B] = -1;
    }
    bucket[a / B][a % B] = x;
    a++;
  }
  while (a <= b && b % B != MAX - 1) {
    if (f2 && udata[b / B] != -1) {
      for (int i = 0; i < MAX; i++)
        bucket[b / B][i] = udata[b / B];
      f2 = 0;
      udata[b / B] = -1;
    }
    bucket[b / B][b % B] = x;
    b--;
  }
  while (a < b) {
    udata[a / B] = x;
    a += B;
  }
}

int find(int x) {
  if (udata[x / B] != -1) {
    for (int i = 0; i < MAX; i++)
      bucket[x / B][i] = udata[x / B];
    udata[x / B] = -1;
  }
  return bucket[x / B][x % B];
}

int main() {
  int n, q, c, s, t, x, ans;
  scanf("%d%d", &n, &q);
  fill(udata, udata + MAX / B, -1);
  fill(data, data + MAX / B, INF);
  fill((int *)bucket, (int *)(bucket + MAX / B), INF);
  while (q--) {
    scanf("%d", &c);
    if (!c) {
      scanf("%d%d%d", &s, &t, &x);
      update(s, t, x);
    } else {
      scanf("%d", &x);
      ans = find(x);
      printf("%d\\n", ans);
    }
  }
  // rep(i,n)printf("%d ", bucket[0][i]);
  return 0;
}