Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- using namespace std;
- #define int long long
- #define vi vector<int>
- #define ii pair<int,int>
- #define fi first
- #define sc second
- #define pb push_back
- #define stoi stoll
- #define popcnt __builtin_popcount
- #define getbit(x, k) ((x >> k) & 1)
- #define all(x) (x).begin(),(x).end()
- #define FOR(i,j,k) for(int i=j; i<k; ++i)
- #define look(a) cerr <<#a<<": "<<a<<endl;
- #define look2(a,b) cerr <<#a<<": "<<a<<" | "<<#b<<": "<<b<< endl;
- void solve()
- {
- int n, g;
- cin >> n >> g;
- if (n == 0) {
- // cerr << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";
- exit(0);
- }
- int vert[n+1], hori[n+1];
- int diag1[n*2], diag2[n*2];
- memset(vert, 0, sizeof(vert));
- memset(hori, 0, sizeof(hori));
- memset(diag1, 0, sizeof(diag1));
- memset(diag2, 0, sizeof(diag2));
- FOR(i,0,g){
- int k,x,y,s,t;
- cin >> k >> x >> y >> s >> t;
- FOR(j,0,k){
- int a = x + j*s;
- int b = y + j*t;
- ++vert[a];
- ++hori[b];
- ++diag1[a+b-1];
- ++diag2[a-b+n];
- }
- }
- int ans = 0;
- FOR(i,1,n+1){
- if (vert[i]) ans += vert[i]-1;
- if (hori[i]) ans += hori[i]-1;
- }
- FOR(i,0,n*2){
- if (diag1[i]) ans += diag1[i]-1;
- if (diag2[i]) ans += diag2[i]-1;
- }
- cout << ans;
- }
- signed main()
- {
- cin.tie(0)->sync_with_stdio(0);
- // freopen("in", "r", stdin);
- // freopen("out", "w", stdout);
- // int T = 1;
- // cin >> T;
- while (true) {
- solve();
- cout << '\n';
- }
- cerr << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";
- }
Advertisement
Add Comment
Please, Sign In to add comment