Submission #1104178

# Submission time Handle Problem Language Result Execution time Memory
1104178 2024-10-23T06:04:57 Z 8pete8 Inspections (NOI23_inspections) C++17
22 / 100
2000 ms 73800 KB
#include<iostream>
#include<stack>
#include<map>
#include<vector>
#include<string>
#include<cassert>
#include<unordered_map>
#include <queue>
#include <cstdint>
#include<cstring>
#include<limits.h>
#include<cmath>
#include<set>
#include<algorithm>
#include <iomanip>
#include<numeric>
#include<bitset>
using namespace std;
#define ll long long
#define f first
#define s second
#define pii pair<int,int>
#define ppii pair<int,pii>
#define vi vector<int>
#define pb push_back
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
#define F(n) for(int i=0;i<n;i++)
#define lb lower_bound
#define ub upper_bound
#define fastio ios::sync_with_stdio(false);cin.tie(NULL);
#pragma GCC optimize ("03,unroll-lopps")
#define int long long
using namespace std;
const int mod=998244353,mxn=2e5+5,inf=1e18,minf=-1e18,lg=30;
//#undef int
int n,k,m,q;
void setIO(string name){		
	ios_base::sync_with_stdio(0); cin.tie(0);		
	freopen((name+".in").c_str(),"r",stdin);		
	freopen((name+".out").c_str(),"w",stdout);	
}
set<int>have;
vector<int>add[mxn+10],rem[mxn+10],start[mxn+10];
vector<pii>allgap;
map<int,vector<int>>gap;
void put(int x,int id){gap[x].pb(id);}
void unput(int x,int id){
	if(gap[x].empty())return;
	if(id-gap[x].back())allgap.pb({x,id-gap[x].back()});
	gap[x].pop_back();
}
int32_t main(){
	fastio
	cin>>n>>m>>q;
	int cnt=0;
	for(int i=0;i<m;i++){
		int l,r;cin>>l>>r;
		add[l].pb(cnt+1-l);
		rem[r+1].pb(cnt+1-l);
		cnt+=(r-l+1);
	}
	for(int i=1;i<=n+1;i++){
		for(auto j:add[i]){
			auto it=have.insert(j).f;
			if(it!=have.begin()&&next(it)!=have.end())unput((*next(it))-(*prev(it)),i);
			if(it!=have.begin())put(j-(*prev(it)),i);
			if(next(it)!=have.end())put((*next(it))-j,i);
		}
		for(auto j:rem[i]){
			auto it=have.find(j);
			if(it!=have.begin()&&next(it)!=have.end())put((*next(it))-(*prev(it)),i);
			if(it!=have.begin())unput(j-(*prev(it)),i);
			if(next(it)!=have.end())unput((*next(it))-j,i);
			have.erase(it);
		}
	}
	vector<pii>qry(q);
	vector<int>sum(q,0);
	for(int i=0;i<q;i++)cin>>qry[i].f,qry[i].s=i;
	sort(all(qry));
	sort(all(allgap));
	int where=allgap.size()-1;
	for(int j=q-1;j>=0;j--){
		while(where>=0&&allgap[where].f-1>=qry[j].f){
			sum[j]+=allgap[where].s;
			where--;
		}
		if(j+1<q)sum[j]+=sum[j+1];
	}
	vector<int>ans(q,0);
	for(int i=0;i<q;i++)ans[qry[i].s]=sum[i];
	for(auto i:ans)cout<<i<<" ";
}
/*
for each m we keep start time-l
then add  at l and del at r

we can keep gap
when add a gap keep the starting time(posi)
when remove we know how long a gap is present by posi-starting time
we can use this to cal answer
*/

Compilation message

Main.cpp:32:40: warning: bad option '-funroll-lopps' to pragma 'optimize' [-Wpragmas]
   32 | #pragma GCC optimize ("03,unroll-lopps")
      |                                        ^
Main.cpp:38:23: warning: bad option '-funroll-lopps' to attribute 'optimize' [-Wattributes]
   38 | void setIO(string name){
      |                       ^
Main.cpp:47:22: warning: bad option '-funroll-lopps' to attribute 'optimize' [-Wattributes]
   47 | void put(int x,int id){gap[x].pb(id);}
      |                      ^
Main.cpp:48:24: warning: bad option '-funroll-lopps' to attribute 'optimize' [-Wattributes]
   48 | void unput(int x,int id){
      |                        ^
Main.cpp:53:14: warning: bad option '-funroll-lopps' to attribute 'optimize' [-Wattributes]
   53 | int32_t main(){
      |              ^
Main.cpp: In function 'void setIO(std::string)':
Main.cpp:40:9: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   40 |  freopen((name+".in").c_str(),"r",stdin);
      |  ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Main.cpp:41:9: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   41 |  freopen((name+".out").c_str(),"w",stdout);
      |  ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 4 ms 14416 KB Output is correct
2 Correct 5 ms 14416 KB Output is correct
3 Correct 4 ms 14584 KB Output is correct
4 Correct 5 ms 14416 KB Output is correct
5 Correct 4 ms 14584 KB Output is correct
6 Execution timed out 2070 ms 14416 KB Time limit exceeded
7 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 4 ms 14416 KB Output is correct
2 Correct 5 ms 14416 KB Output is correct
3 Correct 4 ms 14584 KB Output is correct
4 Correct 5 ms 14416 KB Output is correct
5 Correct 4 ms 14584 KB Output is correct
6 Execution timed out 2070 ms 14416 KB Time limit exceeded
7 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 4 ms 14416 KB Output is correct
2 Correct 4 ms 14416 KB Output is correct
3 Correct 47 ms 21584 KB Output is correct
4 Correct 47 ms 21928 KB Output is correct
5 Correct 854 ms 73800 KB Output is correct
6 Correct 783 ms 70472 KB Output is correct
7 Correct 456 ms 55156 KB Output is correct
8 Correct 4 ms 14416 KB Output is correct
9 Correct 4 ms 14584 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 14416 KB Output is correct
2 Correct 5 ms 14416 KB Output is correct
3 Correct 4 ms 14584 KB Output is correct
4 Correct 5 ms 14416 KB Output is correct
5 Correct 4 ms 14584 KB Output is correct
6 Execution timed out 2070 ms 14416 KB Time limit exceeded
7 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 4 ms 14416 KB Output is correct
2 Correct 5 ms 14416 KB Output is correct
3 Correct 4 ms 14584 KB Output is correct
4 Correct 5 ms 14416 KB Output is correct
5 Correct 4 ms 14584 KB Output is correct
6 Execution timed out 2070 ms 14416 KB Time limit exceeded
7 Halted 0 ms 0 KB -