#include #include #include #include #include using namespace std; const int64_t p = 2000000000000000303; vector ts, tsum; std::random_device rnd; std::mt19937 mt(rnd()); std::normal_distribution<> norm(2, p); int N, Q; unordered_map answer; void init_hash() { ts.resize(N + 1); tsum.resize(N + 1); ts[0] = 1; tsum[0] = 0; for(int i = 0; i < N; i++) { ts[i] = norm(mt); while(__gcd(ts[i], p) != 1) { ts[i] = norm(mt); } tsum[i + 1] = (tsum[i] + ts[i]) % p; } } int main() { cin >> N >> Q; init_hash(); int64_t cur_hash = 0; answer[cur_hash] = 0; for(int i = 0; i < Q; i++) { string c1; cin >> c1; if(c1 == "!"){ int L, R, K; cin >> L >> R >> K; __int128_t tmp = tsum[R] - tsum[L]; tmp = tmp * K % p; if(tmp < 0) tmp += p; cur_hash = (cur_hash + tmp) % p; if(answer.count(cur_hash) == 0) { answer[cur_hash] = i + 1; } } else { cout << answer[cur_hash] << endl; } } }