Submission #350893

# Submission time Handle Problem Language Result Execution time Memory
350893 2021-01-19T09:41:20 Z MHNaderi Spiral (BOI16_spiral) C++14
0 / 100
1 ms 492 KB
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace std;
using namespace __gnu_pbds;
#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
#define all(x) x.begin() , x.end()
#define file_init freopen("input.txt", "r+", stdin); freopen("output.txt", "w+", stdout);
#define random_init mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
#define int long long
#define pb push_back
#define pii pair<int,int>
#define F first
#define S second
const int maxn=3e2,INF=1e18;
int mark[maxn][maxn],dp[maxn][maxn];
pii pls(pii a , pii b){
    return {a.F+b.F,a.S+b.S};
}
int32_t main(){
	ios_base::sync_with_stdio(0);
	int n;
	cin>>n;
	pii dir[4]={ {0,+1} , {+1,0} , {0,-1} , {-1,0} };
	pii go={n+1,n+1};
	int cnt=1;
	int x=1,w=0;
    while(cnt < (2*n+1)*(2*n+1)){
        if(w>1){
            w=0;
            x++;
        }
        int direction=((x-1)%2)*2+w;
        int xx=x;
        while(xx--){
            mark[go.F][go.S]=cnt++;
            go=pls(go,dir[direction]);
        }
        w++;
    }
//    for(int i=1;i<=2*n+1;i++){
//        for(int j=1;j<=2*n+1;j++)
//            cout<<mark[i][j]<<' ';
//        cout<<'\n';
//    }
    for(int i=0;i<=2*n+1;i++){
        dp[0][i]=dp[i][0]=0;
    }
    for(int i=1;i<=2*n+1;i++){
        for(int j=1;j<=2*n+1;j++){
            dp[i][j]=dp[i-1][j]+dp[i][j-1]-dp[i-1][j-1]+mark[i][j];
//            cout<<dp[i][j]<<' ';
        }
//        cout<<'\n';
    }
    int q;
    cin>>q;
    while(q--){
        int x1,x2,y1,y2;
        cin>>x1>>y1>>x2>>y2;
        x1+=n+1;
        x2+=n+1;
        y1+=n+1;
        y2+=n+1;
//        cout<<dp[x2][y2]<<" "<<dp[x2][y1-1]<<" "<<dp[x1-1][y2]<<dp[x1-1][y1-1]<<'\n';
        cout<<dp[y2][x2]-dp[y1-1][x2]-dp[y2][x1-1]+dp[y1-1][x1-1]<<'\n';
    }
	return 0;
}
# Verdict Execution time Memory Grader output
1 Runtime error 1 ms 492 KB Execution killed with signal 11 (could be triggered by violating memory limits)
# Verdict Execution time Memory Grader output
1 Runtime error 1 ms 492 KB Execution killed with signal 11 (could be triggered by violating memory limits)
# Verdict Execution time Memory Grader output
1 Runtime error 1 ms 492 KB Execution killed with signal 11 (could be triggered by violating memory limits)
# Verdict Execution time Memory Grader output
1 Runtime error 1 ms 492 KB Execution killed with signal 11 (could be triggered by violating memory limits)
# Verdict Execution time Memory Grader output
1 Runtime error 1 ms 492 KB Execution killed with signal 11 (could be triggered by violating memory limits)