제출 #1117431

#제출 시각아이디문제언어결과실행 시간메모리
1117431ntdaccode사다리꼴 (balkan11_trapezoid)C++17
100 / 100
170 ms37768 KiB
#include<bits/stdc++.h>
#define fori(i,a,b) for(int i=a;i<=b;i++)
#define pb push_back

using namespace std;
typedef pair<int,int> ii;
typedef tuple<int,int,int> tp;
const int M=1e5+10;
const int N=4e5+10;
const int mod = 30013;

int n,m,a[M],b[M],c[M],d[M];

vector<int> rrh;

struct node
{
   int l,r,idx;
};
vector<node> L[N],R[N];

struct segment_tree
{
   ii t[4 * N];
   ii merged(const ii & l,const ii & r)
   {
      ii ret ={0,0} ;
      ret.first = max(l.first,r.first);
      if(l.first == ret.first) ret.second = l.second;
      if(r.first == ret.first) ret.second += r.second;
      ret.second %= mod;
      return ret;
   }
   void upd(int s, int l, int r, int pos, int val, int cnt)
   {
      if(l > pos || pos > r) return ;
      //cout << l << " " << r << " " << pos << " " << val <<  "\n";
      if(l == r) {
         if(t[s].first == val) t[s].second += cnt;
         else {
               if(val > t[s].first) t[s] = {val,cnt};
         }
         t[s].second %= mod;
         return ;
      }
      int mid = (l + r)/2;
      upd(s *2, l, mid, pos, val, cnt);
      upd(s * 2 + 1, mid + 1, r, pos, val, cnt);
      t[s] = merged(t[s * 2],t[s * 2 + 1]);
   }
   ii get(int s, int l, int r, int u, int v)
   {
      if(l > v || r < u) return {0,0};
      //cout << l << " " << r << " " << u << " " << v << " " << t[s].first <<  "\n";
      if(u <= l && r <= v) return t[s];
      int mid = (l + r)/2;
      return merged(get(s * 2, l, mid, u, v),get(s * 2 + 1, mid + 1, r, u, v));
   }

} T[2];

ii merged(const ii & l,const ii & r)
{
   ii ret ={0,0} ;
   ret.first = max(l.first,r.first);
   if(l.first == ret.first) ret.second = l.second;
   if(r.first == ret.first) ret.second += r.second;
   return ret;
}

int f[M],g[M];

int32_t main()
{
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  if(fopen("1.inp","r"))
  {
    freopen("1.inp","r",stdin);
    freopen("1.out","w",stdout);
  }
  #define task ""
  if(fopen(task".inp","r"))
  {
    freopen(task".inp","r",stdin);
    freopen(task".out","w",stdout);
  }

  cin >> n;
  for(int i = 1;i <= n; i++) {
      cin >> a[i] >> b[i] >> c[i] >> d[i];
      rrh.pb(a[i]),rrh.pb(b[i]),rrh.pb(c[i]),rrh.pb(d[i]);
  }

  sort(rrh.begin(),rrh.end());
  rrh.resize(unique(rrh.begin(),rrh.end()) - rrh.begin());
   m = rrh.size();
  for(int i = 1;i <= n ; i++) {
      a[i] = lower_bound(rrh.begin(),rrh.end(),a[i]) - rrh.begin() + 1;
      b[i] = lower_bound(rrh.begin(),rrh.end(),b[i]) - rrh.begin() + 1;
      c[i] = lower_bound(rrh.begin(),rrh.end(),c[i]) - rrh.begin() + 1;
      d[i] = lower_bound(rrh.begin(),rrh.end(),d[i]) - rrh.begin() + 1;
      L[a[i]].pb({c[i],d[i],i});
      R[b[i]].pb({c[i],d[i],i});
  }

  for(int i = 1;i <= m; i++) {
      for(node pos : L[i]) {
         ii x = T[0].get(1, 1, m, 1, pos.l - 1);
         if(x.first == 0) x.second = 1;
         x.first++;
         x.second %= mod;
         f[pos.idx] = x.first;
         g[pos.idx] = x.second;
         //cerr << T[0].t[1].first << " ";
         //cout << i  << " " << pos.l << " " << pos.r << " ";
         //cout << pos.idx << " " << f[pos.idx] << " " << g[pos.idx] << "sa\n";
      }
      for(node pos : R[i]) {
         T[0].upd(1, 1, m, pos.r, f[pos.idx], g[pos.idx]);
        // cout << i << " " << pos.l << " " << pos.r << " ";
        // cout << pos.idx << " " << f[pos.idx] << " " << g[pos.idx] << "\n";
      }
  }


  cout << T[0].t[1].first << " " << T[0].t[1].second % mod;

}

컴파일 시 표준 에러 (stderr) 메시지

trapezoid.cpp: In function 'int32_t main()':
trapezoid.cpp:80:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   80 |     freopen("1.inp","r",stdin);
      |     ~~~~~~~^~~~~~~~~~~~~~~~~~~
trapezoid.cpp:81:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   81 |     freopen("1.out","w",stdout);
      |     ~~~~~~~^~~~~~~~~~~~~~~~~~~~
trapezoid.cpp:86:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   86 |     freopen(task".inp","r",stdin);
      |     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~
trapezoid.cpp:87:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   87 |     freopen(task".out","w",stdout);
      |     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...