Number of Smaller permutations












1












$begingroup$


I'm practicing programming and I found following problem that I don't know how to solve:



We have 2 sequences A and B that both have length N. We should find number of different ways to permute sequence A such that it is lexicographically smaller than the sequence B.



Sequence (X_1,X_2,...,X_k) is strictly lexicographically smaller then sequence (Y_1,Y_2,...,Y_k), if there exists and index p (1<=p<=k) such that X_p < Y_p and (X_q=Y_q) for all 1 <= q < p



A permutation X of A is considered different form another permutation Y of A if there exists an index i (1<=i<=N) such that X_i != Y_i



For example A(2,2,3,3) has 6 different permutations



1<=N<=100000



1<=A_i<=200000



1<=B_i<=200000



Output should be answer mod 1000000007



I cant find general formula to calculate answer. Can someone please help me?



Thank you all in advance.










share|cite|improve this question









$endgroup$

















    1












    $begingroup$


    I'm practicing programming and I found following problem that I don't know how to solve:



    We have 2 sequences A and B that both have length N. We should find number of different ways to permute sequence A such that it is lexicographically smaller than the sequence B.



    Sequence (X_1,X_2,...,X_k) is strictly lexicographically smaller then sequence (Y_1,Y_2,...,Y_k), if there exists and index p (1<=p<=k) such that X_p < Y_p and (X_q=Y_q) for all 1 <= q < p



    A permutation X of A is considered different form another permutation Y of A if there exists an index i (1<=i<=N) such that X_i != Y_i



    For example A(2,2,3,3) has 6 different permutations



    1<=N<=100000



    1<=A_i<=200000



    1<=B_i<=200000



    Output should be answer mod 1000000007



    I cant find general formula to calculate answer. Can someone please help me?



    Thank you all in advance.










    share|cite|improve this question









    $endgroup$















      1












      1








      1





      $begingroup$


      I'm practicing programming and I found following problem that I don't know how to solve:



      We have 2 sequences A and B that both have length N. We should find number of different ways to permute sequence A such that it is lexicographically smaller than the sequence B.



      Sequence (X_1,X_2,...,X_k) is strictly lexicographically smaller then sequence (Y_1,Y_2,...,Y_k), if there exists and index p (1<=p<=k) such that X_p < Y_p and (X_q=Y_q) for all 1 <= q < p



      A permutation X of A is considered different form another permutation Y of A if there exists an index i (1<=i<=N) such that X_i != Y_i



      For example A(2,2,3,3) has 6 different permutations



      1<=N<=100000



      1<=A_i<=200000



      1<=B_i<=200000



      Output should be answer mod 1000000007



      I cant find general formula to calculate answer. Can someone please help me?



      Thank you all in advance.










      share|cite|improve this question









      $endgroup$




      I'm practicing programming and I found following problem that I don't know how to solve:



      We have 2 sequences A and B that both have length N. We should find number of different ways to permute sequence A such that it is lexicographically smaller than the sequence B.



      Sequence (X_1,X_2,...,X_k) is strictly lexicographically smaller then sequence (Y_1,Y_2,...,Y_k), if there exists and index p (1<=p<=k) such that X_p < Y_p and (X_q=Y_q) for all 1 <= q < p



      A permutation X of A is considered different form another permutation Y of A if there exists an index i (1<=i<=N) such that X_i != Y_i



      For example A(2,2,3,3) has 6 different permutations



      1<=N<=100000



      1<=A_i<=200000



      1<=B_i<=200000



      Output should be answer mod 1000000007



      I cant find general formula to calculate answer. Can someone please help me?



      Thank you all in advance.







      combinatorics permutations programming






      share|cite|improve this question













      share|cite|improve this question











      share|cite|improve this question




      share|cite|improve this question










      asked Jan 24 at 4:17









      JimJim

      112




      112






















          0






          active

          oldest

          votes











          Your Answer





          StackExchange.ifUsing("editor", function () {
          return StackExchange.using("mathjaxEditing", function () {
          StackExchange.MarkdownEditor.creationCallbacks.add(function (editor, postfix) {
          StackExchange.mathjaxEditing.prepareWmdForMathJax(editor, postfix, [["$", "$"], ["\\(","\\)"]]);
          });
          });
          }, "mathjax-editing");

          StackExchange.ready(function() {
          var channelOptions = {
          tags: "".split(" "),
          id: "69"
          };
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function() {
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled) {
          StackExchange.using("snippets", function() {
          createEditor();
          });
          }
          else {
          createEditor();
          }
          });

          function createEditor() {
          StackExchange.prepareEditor({
          heartbeatType: 'answer',
          autoActivateHeartbeat: false,
          convertImagesToLinks: true,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: 10,
          bindNavPrevention: true,
          postfix: "",
          imageUploader: {
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          },
          noCode: true, onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          });


          }
          });














          draft saved

          draft discarded


















          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmath.stackexchange.com%2fquestions%2f3085453%2fnumber-of-smaller-permutations%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown

























          0






          active

          oldest

          votes








          0






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes
















          draft saved

          draft discarded




















































          Thanks for contributing an answer to Mathematics Stack Exchange!


          • Please be sure to answer the question. Provide details and share your research!

          But avoid



          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.


          Use MathJax to format equations. MathJax reference.


          To learn more, see our tips on writing great answers.




          draft saved


          draft discarded














          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmath.stackexchange.com%2fquestions%2f3085453%2fnumber-of-smaller-permutations%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown





















































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown

































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown







          Popular posts from this blog

          Mario Kart Wii

          What does “Dominus providebit” mean?

          Antonio Litta Visconti Arese