#include #include #include #include #include using namespace std; typedef unsigned long long ULL; const int N = 1000010; const ULL P = 1000000007ULL; ULL r1[N], r2[N], pre1[N], pre2[N]; ULL h1, h2; int n, q; map mp; int main() { mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count()); scanf("%d%d", &n, &q); for (int i = 0; i < n; ++i) { r1[i] = rng(); r2[i] = rng(); } for (int i = 0; i < n; ++i) { pre1[i + 1] = pre1[i] + r1[i]; pre2[i + 1] = pre2[i] + r2[i]; } mp[0] = 0; for (int i = 1; i <= q; ++i) { char type; scanf(" %c", &type); if (type == '!') { int l, r, k; scanf("%d%d%d", &l, &r, &k); h1 += (ULL) k * (pre1[r] - pre1[l]); h2 += (ULL) k * (pre2[r] - pre2[l]); ULL key = h1 * P + h2; if (!mp.count(key)) mp[key] = i; } else { printf("%d\n", mp[h1 * P + h2]); } } return 0; }