#include using namespace std; #define rep(i,a,b) for(int i=a;i Hash; int N, Q; //----------------------------------------------------------------- Hash imos[1010101]; void pre() { imos[0] = { 0, 0 }; rep(i, 1, 1010101) imos[i + 1] = {(imos[i].first * add0 + add0) % mo0, (imos[i].second * add1 + add1) % mo1 }; } Hash calc(Hash h, int L, int R, int K) { Hash one = imos[R]; if (0 < L) one = { one.first - imos[L].first, one.second - imos[L].second }; one.first = (one.first + mo0) % mo0; one.second = (one.second + mo1) % mo1; return{ (h.first + one.first * ((K + mo0) % mo0)) % mo0, (h.second + one.second * ((K + mo1) % mo1)) % mo1 }; } //----------------------------------------------------------------- map ans; int main() { cin.tie(0); ios::sync_with_stdio(false); cin >> N >> Q; pre(); Hash h = { 0, 0 }; ans[h] = 0; rep(q, 1, Q + 1) { char t; cin >> t; if (t == '!') { int L, R, K; cin >> L >> R >> K; h = calc(h, L, R, K); if (ans.count(h) == 0) ans[h] = q; } else { printf("%d\n", ans[h]); } } }