제출 #807342

#제출 시각아이디문제언어결과실행 시간메모리
807342BenmathRectangles (IOI19_rect)C++14
0 / 100
375 ms484 KiB
#include "rect.h" #include <cstdio> #include <unistd.h> #include <cassert> #include <string> #include<bits/stdc++.h> using namespace std; int treemax[10001]; int treemin[10001]; void updatemax(int node,int start,int end,int idx,int val){ if(start==end){ treemax[node]=val; }else{ int mid=(start+end)/2; if(start<=idx and idx<=mid){ updatemax(2*node,start,mid,idx,val); }else{ updatemax(2*node+1,mid+1,end,idx,val); } treemax[node]=max(treemax[2*node],treemax[2*node+1]); } } void updatemin(int node,int start,int end,int idx,int val){ if(start==end){ treemin[node]=val; }else{ int mid=(start+end)/2; if(start<=idx and idx<=mid){ updatemin(2*node,start,mid,idx,val); }else{ updatemin(2*node+1,mid+1,end,idx,val); } treemin[node]=min(treemin[2*node],treemin[2*node+1]); } } int querymax(int node,int start,int end,int l,int r){ if(l>end or r<start){ return 0; } if(l<=start and end<=r){ return treemax[node]; } int mid=(start+end)/2; return max(querymax(2*node,start,mid,l,r),querymax(2*node+1,mid+1,end,l,r)); } int querymin(int node,int start,int end,int l,int r){ if(l>end or r<start){ return 1e9; } if(l<=start and end<=r){ return treemin[node]; } int mid=(start+end)/2; return min(querymin(2*node,start,mid,l,r),querymin(2*node+1,mid+1,end,l,r)); } long long count_rectangles(std::vector<std::vector<int> > a) { int m=a[0].size(); int n=a.size(); if(n<=2 or m<=2){ return 0; } for(int i=0;i<m;i++){ if(a[1][i]<a[0][i] and a[1][i]<a[2][i]){ updatemin(1,0,m-1,i,1); } updatemax(1,0,m-1,i,a[1][i]); } int ans=0; for(int j=1;j<(m-1);j++){ for(int k=j;k<(m-1);k++){ int x=querymin(1,0,m-1,j,k); if(x==1){ int y=querymax(1,0,n-1,j,k); if(y<a[1][j-1] and y<a[1][k+1]){ ans++; } } } } return ans; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...